summaryrefslogtreecommitdiff
path: root/internal/configuration/sources.go
diff options
context:
space:
mode:
Diffstat (limited to 'internal/configuration/sources.go')
-rw-r--r--internal/configuration/sources.go31
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
}
}