diff --git a/env.go b/env.go index 748bfeeba8..0cf6857ef6 100644 --- a/env.go +++ b/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 +} diff --git a/go.mod b/go.mod index 1d883eb8b0..70b2b1bee7 100644 --- a/go.mod +++ b/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 diff --git a/vendor/modules.txt b/vendor/modules.txt index e8e79b650f..e72afd531d 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -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