Skip to content

Commit

Permalink
Evaluate http config if value set as env variable
Browse files Browse the repository at this point in the history
  • Loading branch information
vivekweb2013 committed May 24, 2022
1 parent b6a723d commit 3060526
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"net/url"
"os"
"path"
"strings"

"github.com/batnoter/batnoter-api/internal/config"
"github.com/iamolegga/enviper"
Expand Down Expand Up @@ -76,8 +77,19 @@ func initConfig() {
if conf.Database.URL != "" {
// if url is set then the values of host, port, dbname, username, password, driver-name
// will be overridden with their respective values from url string.
logrus.Info("using db connection url")
overrideDatabaseConfigs()
}

// evaluate configs with values set as environment variable
if strings.HasPrefix(conf.HTTPServer.Host, "$") {
logrus.Infof("evaluating http host config from env variable: %s", conf.HTTPServer.Host)
conf.HTTPServer.Host = os.Expand(conf.HTTPServer.Host, os.Getenv)
}
if strings.HasPrefix(conf.HTTPServer.Port, "$") {
logrus.Infof("evaluating http port config from env variable: %s", conf.HTTPServer.Port)
conf.HTTPServer.Port = os.Expand(conf.HTTPServer.Port, os.Getenv)
}
}

func overrideDatabaseConfigs() {
Expand Down

0 comments on commit 3060526

Please sign in to comment.