diff --git a/internal/config/config.go b/internal/config/config.go index a3b34b0..e3bb4f2 100644 --- a/internal/config/config.go +++ b/internal/config/config.go @@ -2,6 +2,7 @@ package config import ( "errors" + "flag" "fmt" "os" @@ -27,13 +28,26 @@ func MustLoad(version, commit, date string) *Config { } func loadConfig() (*Config, error) { - if _, err := os.Stat(ConfigBasePath); os.IsNotExist(err) { + var configPath string + + flag.StringVar(&configPath, "config_path", configPath, "Path to config file") + flag.Parse() + + if configPath == "" { + if path := os.Getenv("CONFIG_PATH"); path != "" { + configPath = path + } else { + configPath = ConfigBasePath + } + } + + if _, err := os.Stat(configPath); os.IsNotExist(err) { return nil, fmt.Errorf("no config file found") } var localConfig LocalDeploy - if err := cleanenv.ReadConfig(ConfigBasePath, &localConfig); err != nil { + if err := cleanenv.ReadConfig(configPath, &localConfig); err != nil { return nil, fmt.Errorf("error reading local config: %w", err) } @@ -45,7 +59,7 @@ func loadConfig() (*Config, error) { var cfg Config - if err := cleanenv.ReadConfig(ConfigBasePath, &cfg); err != nil { + if err := cleanenv.ReadConfig(configPath, &cfg); err != nil { return nil, err } diff --git a/internal/config/constants.go b/internal/config/constants.go index 18b4ae9..48b874d 100644 --- a/internal/config/constants.go +++ b/internal/config/constants.go @@ -1,5 +1,5 @@ package config const ( - ConfigBasePath = "/home/alexorel/work/Molva/molva-backend/.build/config/local.example.yaml" + ConfigBasePath = "/config.yaml" )