diff --git a/.gitignore b/.gitignore index eda73ad..d46b0b2 100644 --- a/.gitignore +++ b/.gitignore @@ -24,4 +24,5 @@ go.work pomme test.db test.sqlite -.dccache \ No newline at end of file +.dccache +config.yaml \ No newline at end of file diff --git a/internal/configuration.go b/internal/configuration.go index 15a44df..254d9af 100644 --- a/internal/configuration.go +++ b/internal/configuration.go @@ -49,19 +49,30 @@ type Config struct { var config Config func ReadConfig() (*Config, error) { - configPath := xdg.ConfigHome + "/pomme/config.yaml" + var ( + data []byte + err error + defaultConfigPath string + ) - if configPath != "" { - data, err := os.ReadFile(filepath.Clean(configPath)) - if err != nil { - return &Config{}, fmt.Errorf("unable to read config file: %w", err) - } + defaultConfigPath = xdg.ConfigHome + "/pomme/config.yaml" + + if data, err = os.ReadFile(filepath.Clean(defaultConfigPath)); err == nil { + if err = yaml.Unmarshal(data, &config); err != nil { - err = yaml.Unmarshal(data, &config) - if err != nil { return &Config{}, fmt.Errorf("unable to unmarshal config file: %w", err) } + return &config, nil } - return &config, nil + if data, err = os.ReadFile(filepath.Clean("./config.yaml")); err == nil { + if err = yaml.Unmarshal(data, &config); err != nil { + + return &Config{}, fmt.Errorf("unable to unmarshal config file: %w", err) + } + return &config, nil + } + + return &Config{}, fmt.Errorf("unable to read config file: %w", err) + }