components/resolver: Use database instead of file approach

This commit is contained in:
Tom Wiesing 2022-10-05 16:35:47 +02:00
parent f6b38f055d
commit 32107265d4
No known key found for this signature in database
10 changed files with 165 additions and 103 deletions

View file

@ -82,6 +82,29 @@ func hasAnyPrefix(candidate string, prefixes []string) bool {
)
}
var PrefixConfigKey MetaKey = "prefix"
// Prefixes returns the prefixes for the instance
func (wisski *WissKI) PrefixesCached() (results []string, err error) {
err = wisski.Metadata().GetAll(PrefixConfigKey, func(index, total int) any {
if results == nil {
results = make([]string, total)
}
return &results[index]
})
return
}
// UpdatePrefixes updates the cached prefixes of this instance
func (wisski *WissKI) UpdatePrefixes() error {
prefixes, err := wisski.Prefixes()
if err != nil {
return err
}
return wisski.Metadata().SetAll(PrefixConfigKey, slicesx.AsAny(prefixes)...)
}
// PrefixConfig returns the prefix config belonging to this instance.
func (wisski *WissKI) PrefixConfig() (config string, err error) {
// if the user requested to skip the prefix, then don't do anything with it!