Skip to content

Commit 554240f

Browse files
WillNilgesWillard Nilges
and
Willard Nilges
authored
Use godotenv to load env vars (#50)
* Use godotenv to load env vars * Add godotenv to automatically load env vars --------- Co-authored-by: Willard Nilges <[email protected]>
1 parent 8429064 commit 554240f

File tree

3 files changed

+12
-1
lines changed

3 files changed

+12
-1
lines changed

site/go.mod

+2
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ require (
77
github.com/gin-gonic/gin v1.7.7
88
)
99

10+
require github.com/joho/godotenv v1.5.1 // indirect
11+
1012
require (
1113
github.com/gin-contrib/sse v0.1.0 // indirect
1214
github.com/go-playground/locales v0.14.0 // indirect

site/go.sum

+2
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ github.com/google/go-cmp v0.5.7/go.mod h1:n+brtR0CgQNWTVd5ZUFpTBC8YFBDLK/h/bpaJ8
3030
github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
3131
github.com/gorilla/websocket v1.4.2 h1:+/TMaTYc4QFitKJxsQ7Yye35DkWvkdLcvGKqM+x0Ufc=
3232
github.com/gorilla/websocket v1.4.2/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE=
33+
github.com/joho/godotenv v1.5.1 h1:7eLL/+HRGLY0ldzfGMeQkb7vMd0as4CfYvUVzLqw0N0=
34+
github.com/joho/godotenv v1.5.1/go.mod h1:f4LDr5Voq0i2e/R5DDNOoa2zzDfwtkZa6DnEwAbqwq4=
3335
github.com/json-iterator/go v1.1.9/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4=
3436
github.com/json-iterator/go v1.1.12 h1:PV8peI4a0ysnczrg+LtxykD8LfKY9ML6u2jnxaEnrnM=
3537
github.com/json-iterator/go v1.1.12/go.mod h1:e30LSqwooZae/UwlEbR2852Gd8hjQvJoHmT4TnhNGBo=

site/main.go

+8-1
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,17 @@ import (
66
"strconv"
77

88
"github.com/gin-gonic/gin"
9+
"github.com/joho/godotenv"
910
)
1011

1112
func main() {
12-
// Get environment variables
13+
// Load environment variables, one way or another
14+
err := godotenv.Load()
15+
if err != nil {
16+
fmt.Println("Couldn't load .env file! Please ensure that you have a .env in this directory. Check main.go for expected variables.")
17+
return
18+
}
19+
1320
var broker, brokerMissing = os.LookupEnv("LMI_BROKER")
1421
var port, portMissing = os.LookupEnv("LMI_BROKER_PORT")
1522
var portNumber = 1883 // Set a reasonable default.

0 commit comments

Comments
 (0)