From e272d9f7ad39eda5c97d3c4a34b0e80521c55f27 Mon Sep 17 00:00:00 2001 From: Al Hoang <13622+hoanga@users.noreply.github.com> Date: Mon, 7 Sep 2020 08:45:36 -0500 Subject: [PATCH] MF-435 - Add support for env file loading (#1223) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * NO-ISSUE - add support for env file loading Signed-off-by: Al Hoang * update go mod Signed-off-by: Al Hoang Co-authored-by: Dušan Borovčanin --- env.go | 8 ++++++++ go.mod | 1 + vendor/modules.txt | 1 + 3 files changed, 10 insertions(+) diff --git a/env.go b/env.go index 748bfeeb..0cf6857e 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 1d883eb8..70b2b1be 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 e8e79b65..e72afd53 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