From abf2f1ff35c88e681408ebe35a7cc16ee1707871 Mon Sep 17 00:00:00 2001 From: Stephanie Gredell Date: Sat, 2 Nov 2024 19:28:51 -0700 Subject: [PATCH] Add a config package that will handle how we load env variables --- config/env.go | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 config/env.go diff --git a/config/env.go b/config/env.go new file mode 100644 index 0000000..0204ab7 --- /dev/null +++ b/config/env.go @@ -0,0 +1,18 @@ +package config + +import ( + "github.com/joho/godotenv" + "os" +) + +func GetEnvVar(key string) string { + if os.Getenv("ENVIRONMENT") == "DEV" { + err := godotenv.Load() + if err != nil { + // we're going to panic because without the env variables, our app couldn't run anyways + panic("Error loading environment variable") + } + } + + return os.Getenv(key) +}