Skip to content

Commit

Permalink
Remove env prefix from config
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
sagikazarmark committed Apr 9, 2020
1 parent 2e6196b commit 6884cbd
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 6 deletions.
4 changes: 1 addition & 3 deletions cmd/modern-go-application/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package main

import (
"errors"
"fmt"
"os"
"strings"
"time"
Expand Down Expand Up @@ -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()
Expand Down
3 changes: 0 additions & 3 deletions cmd/modern-go-application/vars.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

0 comments on commit 6884cbd

Please sign in to comment.