From 39940c9f6bb388b76b0abcf35fb2a8be4c4550c1 Mon Sep 17 00:00:00 2001 From: Adhityaa Date: Thu, 21 Jun 2018 21:08:28 +0530 Subject: [PATCH] api: config files have lower precedence than envvars --- api/config.go | 12 ++++++------ api/config_file.go | 4 ++++ 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/api/config.go b/api/config.go index 874ca45..4b72698 100644 --- a/api/config.go +++ b/api/config.go @@ -38,12 +38,6 @@ func parseConfig() error { "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 { if os.Getenv("COMMENTO_"+key) == "" { 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 for _, env := range []string{"POSTGRES", "PORT", "ORIGIN"} { if os.Getenv(env) == "" { diff --git a/api/config_file.go b/api/config_file.go index 1797054..8303c6b 100644 --- a/api/config_file.go +++ b/api/config_file.go @@ -41,6 +41,10 @@ func configFileLoad(filepath string) error { continue } + if os.Getenv(key[9:]) != "" { + continue + } + os.Setenv(key[9:], value) }