diff options
| author | James Elliott <james-d-elliott@users.noreply.github.com> | 2025-02-18 20:38:36 +1100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-02-18 09:38:36 +0000 |
| commit | a9d1986fa9dec8701ee73b05aa99781f4bbe5f18 (patch) | |
| tree | bbcef1a55483271f43308179d4fd09ef8a894131 /internal/configuration/sources.go | |
| parent | 7ac3c6a4f3945c3c4272bac717addd1ef598b2b9 (diff) | |
feat(configuration): reusable definitions (#8077)
This adds reusable definitions into the mix for the configuration. This replaces the existing networks section for the access_control section and is automatically remapped for users.
Signed-off-by: James Elliott <james-d-elliott@users.noreply.github.com>
Diffstat (limited to 'internal/configuration/sources.go')
| -rw-r--r-- | internal/configuration/sources.go | 31 |
1 files changed, 24 insertions, 7 deletions
diff --git a/internal/configuration/sources.go b/internal/configuration/sources.go index bd8b559b2..c5dd1fe0d 100644 --- a/internal/configuration/sources.go +++ b/internal/configuration/sources.go @@ -20,8 +20,10 @@ import ( // accessing this path it also returns an error. func NewFileSource(path string) (source *FileSource) { return &FileSource{ - koanf: koanf.New(constDelimiter), - path: path, + koanf: koanf.New(constDelimiter), + provider: FilteredFileProvider(path), + providers: make(map[string]*FilteredFile), + path: path, } } @@ -29,9 +31,11 @@ func NewFileSource(path string) (source *FileSource) { // an issue accessing this path it also returns an error. func NewFilteredFileSource(path string, filters ...BytesFilter) (source *FileSource) { return &FileSource{ - koanf: koanf.New(constDelimiter), - path: path, - filters: filters, + koanf: koanf.New(constDelimiter), + provider: FilteredFileProvider(path, filters...), + providers: make(map[string]*FilteredFile), + path: path, + filters: filters, } } @@ -83,7 +87,7 @@ func (s *FileSource) Load(val *schema.StructValidator) (err error) { return s.loadDir(val) } - return s.koanf.Load(FilteredFileProvider(s.path, s.filters...), yaml.Parser()) + return s.koanf.Load(s.provider, yaml.Parser()) } func (s *FileSource) loadDir(_ *schema.StructValidator) (err error) { @@ -93,6 +97,11 @@ func (s *FileSource) loadDir(_ *schema.StructValidator) (err error) { return err } + var ( + provider *FilteredFile + ok bool + ) + for _, entry := range entries { if entry.IsDir() { continue @@ -100,9 +109,17 @@ func (s *FileSource) loadDir(_ *schema.StructValidator) (err error) { name := entry.Name() + file := filepath.Join(s.path, name) + switch ext := filepath.Ext(name); ext { case extYML, extYAML: - if err = s.koanf.Load(FilteredFileProvider(filepath.Join(s.path, name), s.filters...), yaml.Parser()); err != nil { + if provider, ok = s.providers[file]; !ok { + provider = FilteredFileProvider(file, s.filters...) + + s.providers[file] = provider + } + + if err = s.koanf.Load(provider, yaml.Parser()); err != nil { return err } } |
