diff options
author | Alan Pearce | 2024-05-09 18:24:25 +0200 |
---|---|---|
committer | Alan Pearce | 2024-05-09 19:27:57 +0200 |
commit | 14c1ddaf7c5468c5966b0c1585f19a5ff39c206d (patch) | |
tree | 91b7910c62fd9bc2bcf89c78847c311f80827a0d /internal/config | |
parent | fbc4c583a4e2759d6b8cdbb98de2c769918ddac8 (diff) | |
download | searchix-14c1ddaf7c5468c5966b0c1585f19a5ff39c206d.tar.lz searchix-14c1ddaf7c5468c5966b0c1585f19a5ff39c206d.tar.zst searchix-14c1ddaf7c5468c5966b0c1585f19a5ff39c206d.zip |
feat: enable setting config file path via command line
Diffstat (limited to 'internal/config')
-rw-r--r-- | internal/config/config.go | 17 |
1 files changed, 9 insertions, 8 deletions
diff --git a/internal/config/config.go b/internal/config/config.go index 2cf5def..5801847 100644 --- a/internal/config/config.go +++ b/internal/config/config.go @@ -5,7 +5,6 @@ import ( "maps" "net/url" "os" - "searchix/internal/file" "searchix/internal/importer" "time" @@ -93,15 +92,16 @@ var defaultConfig = Config{ }, } -func GetConfig() (*Config, error) { +func GetConfig(filename string) (*Config, error) { config := defaultConfig - slog.Debug("reading config.toml") - f, err := os.Open("config.toml") - if err := file.NeedNotExist(err); err != nil { - return nil, errors.Wrap(err, "reading config.toml failed") - } - if f != nil { + if filename != "" { + slog.Debug("reading config", "filename", filename) + f, err := os.Open(filename) + if err != nil { + return nil, errors.Wrap(err, "reading config failed") + } defer f.Close() + dec := toml.NewDecoder(f) err = dec.Decode(&config) if err != nil { @@ -113,6 +113,7 @@ func GetConfig() (*Config, error) { return nil, errors.Wrap(err, "config error") } } + maps.DeleteFunc(config.Sources, func(_ string, v importer.Source) bool { return !v.Enable }) |