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:
parent
26c944b5c3
commit
e272d9f7ad
8
env.go
8
env.go
|
@ -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
1
go.mod
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue