diff --git a/util/config.go b/util/config.go index a29b506..8d85822 100644 --- a/util/config.go +++ b/util/config.go @@ -2,27 +2,45 @@ package util import ( "encoding/json" + "io/fs" + "path/filepath" + "io" "os" ) -func ReadConfigs(name string) ([]*Config, error) { - file, err := os.Open(name) +func ReadConfigs(cfgPath string) ([]*Config, error) { + var configs []*Config - if err != nil { - return nil, err - } - defer file.Close() + err := filepath.Walk(cfgPath, func(path string, info fs.FileInfo, err error) error { + if info.IsDir() { + return nil + } - bytes, _ := io.ReadAll(file) + file, err := os.Open(path) - var config []*Config - err = json.Unmarshal(bytes, &config) + if err != nil { + return nil + } + defer file.Close() - if err != nil { - return nil, err - } - return config, nil + bytes, err := io.ReadAll(file) + if err != nil { + return nil + } + + var config *Config + err = json.Unmarshal(bytes, &config) + + if err != nil { + return nil + } + + configs = append(configs, config) + return nil + }) + + return configs, err } func SaveConfig(name string, config Config) error {