MF-435 - Add support for env file loading (#1223)

* 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>
This commit is contained in:
Al Hoang 2020-09-07 08:45:36 -05:00 committed by GitHub
parent 26c944b5c3
commit e272d9f7ad
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 10 additions and 0 deletions

8
env.go
View File

@ -5,6 +5,8 @@ package mainflux
import (
"os"
"github.com/subosito/gotenv"
)
// Env reads specified environment variable. If no value has been found,
@ -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
go.mod
View File

@ -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

1
vendor/modules.txt vendored
View File

@ -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