From 6884cbda7937372acbfa5e7b3516dbf97452a499 Mon Sep 17 00:00:00 2001 From: Mark Sagi-Kazar Date: Thu, 9 Apr 2020 17:46:10 +0200 Subject: [PATCH] Remove env prefix from config Environment variable prefix config allowed overriding the prefix without changing boilerplate code. Experience showed that these tricks are not that useful. Also, a default prefix will probably never be the correct one, so I decided to remove it. --- cmd/modern-go-application/config.go | 4 +--- cmd/modern-go-application/vars.go | 3 --- 2 files changed, 1 insertion(+), 6 deletions(-) diff --git a/cmd/modern-go-application/config.go b/cmd/modern-go-application/config.go index f6d74473..0dce84c5 100644 --- a/cmd/modern-go-application/config.go +++ b/cmd/modern-go-application/config.go @@ -2,7 +2,6 @@ package main import ( "errors" - "fmt" "os" "strings" "time" @@ -128,10 +127,9 @@ func (c telemetryConfig) Validate() error { func configure(v *viper.Viper, p *pflag.FlagSet) { // Viper settings v.AddConfigPath(".") - v.AddConfigPath(fmt.Sprintf("$%s_CONFIG_DIR/", strings.ToUpper(envPrefix))) + v.AddConfigPath("$CONFIG_DIR/") // Environment variable settings - v.SetEnvPrefix(envPrefix) v.SetEnvKeyReplacer(strings.NewReplacer(".", "_", "-", "_")) v.AllowEmptyEnv(true) v.AutomaticEnv() diff --git a/cmd/modern-go-application/vars.go b/cmd/modern-go-application/vars.go index 77781e64..c58ecc3a 100644 --- a/cmd/modern-go-application/vars.go +++ b/cmd/modern-go-application/vars.go @@ -9,7 +9,4 @@ const ( // friendlyAppName is the visible name of the application. friendlyAppName = "Modern Go Application" - - // envPrefix is prepended to environment variables when processing configuration. - envPrefix = "app" )