Skip to content

Commit

Permalink
add env from machine override
Browse files Browse the repository at this point in the history
  • Loading branch information
janishar committed Jun 30, 2024
1 parent aa8acbc commit 6222411
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 3 deletions.
6 changes: 5 additions & 1 deletion config/env.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,14 @@ type Env struct {
TokenAudience string `mapstructure:"TOKEN_AUDIENCE"`
}

func NewEnv(filename string) *Env {
func NewEnv(filename string, override bool) *Env {
env := Env{}
viper.SetConfigFile(filename)

if override {
viper.AutomaticEnv()
}

err := viper.ReadInConfig()
if err != nil {
log.Fatal("Error reading environment file", err)
Expand Down
2 changes: 1 addition & 1 deletion startup/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (
type Shutdown = func()

func Server() {
env := config.NewEnv(".env")
env := config.NewEnv(".env", true)
router, _, shutdown := create(env)
defer shutdown()
router.Start(env.ServerHost, env.ServerPort)
Expand Down
2 changes: 1 addition & 1 deletion startup/testserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
type Teardown = func()

func TestServer() (network.Router, Module, Teardown) {
env := config.NewEnv("../.test.env")
env := config.NewEnv("../.test.env", false)
router, module, shutdown := create(env)
ts := httptest.NewServer(router.GetEngine())
teardown := func() {
Expand Down

0 comments on commit 6222411

Please sign in to comment.