Skip to content

Commit

Permalink
MF-435 - Add support for env file loading (#1223)
Browse files Browse the repository at this point in the history
* NO-ISSUE - add support for env file loading

Signed-off-by: Al Hoang <hoanga@gmail.com>

* update go mod

Signed-off-by: Al Hoang <hoanga@gmail.com>

Co-authored-by: Dušan Borovčanin <dusan.borovcanin@mainflux.com>
  • Loading branch information
hoanga and dborovcanin authored Sep 7, 2020
1 parent 26c944b commit e272d9f
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 0 deletions.
8 changes: 8 additions & 0 deletions env.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ package mainflux

import (
"os"

"github.com/subosito/gotenv"
)

// Env reads specified environment variable. If no value has been found,
Expand All @@ -16,3 +18,9 @@ func Env(key, fallback string) string {

return fallback
}

// LoadEnvFile loads environment variables defined in an .env formatted file.
func LoadEnvFile(envfilepath string) error {
err := gotenv.Load(envfilepath)
return err
}
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ require (
github.com/spf13/cobra v1.0.0
github.com/spf13/viper v1.7.0
github.com/stretchr/testify v1.6.1
github.com/subosito/gotenv v1.2.0
github.com/uber/jaeger-client-go v2.24.0+incompatible
go.mongodb.org/mongo-driver v1.3.5
golang.org/x/crypto v0.0.0-20200709230013-948cd5f35899
Expand Down
1 change: 1 addition & 0 deletions vendor/modules.txt
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,7 @@ github.com/spf13/viper
github.com/stretchr/testify/assert
github.com/stretchr/testify/require
# github.com/subosito/gotenv v1.2.0
## explicit
github.com/subosito/gotenv
# github.com/uber/jaeger-client-go v2.24.0+incompatible
## explicit
Expand Down

0 comments on commit e272d9f

Please sign in to comment.