api: config files have lower precedence than envvars

This commit is contained in:
Adhityaa 2018-06-21 21:08:28 +05:30
parent bb24f62b9c
commit 39940c9f6b
2 changed files with 10 additions and 6 deletions

View File

@ -38,12 +38,6 @@ func parseConfig() error {
"GOOGLE_SECRET": "", "GOOGLE_SECRET": "",
} }
if os.Getenv("COMMENTO_CONFIG_FILE") != "" {
if err := configFileLoad(os.Getenv("COMMENTO_CONFIG_FILE")); err != nil {
return err
}
}
for key, value := range defaults { for key, value := range defaults {
if os.Getenv("COMMENTO_"+key) == "" { if os.Getenv("COMMENTO_"+key) == "" {
os.Setenv(key, value) os.Setenv(key, value)
@ -52,6 +46,12 @@ func parseConfig() error {
} }
} }
if os.Getenv("CONFIG_FILE") != "" {
if err := configFileLoad(os.Getenv("CONFIG_FILE")); err != nil {
return err
}
}
// Mandatory config parameters // Mandatory config parameters
for _, env := range []string{"POSTGRES", "PORT", "ORIGIN"} { for _, env := range []string{"POSTGRES", "PORT", "ORIGIN"} {
if os.Getenv(env) == "" { if os.Getenv(env) == "" {

View File

@ -41,6 +41,10 @@ func configFileLoad(filepath string) error {
continue continue
} }
if os.Getenv(key[9:]) != "" {
continue
}
os.Setenv(key[9:], value) os.Setenv(key[9:], value)
} }