From d76aa4ca11f8ee07dd619403e9aecd41f22846ed Mon Sep 17 00:00:00 2001 From: httpjamesm Date: Wed, 28 Dec 2022 11:57:58 -0500 Subject: [PATCH] feat!: run checks on env variables --- env/checks.go | 16 ++++++++++++++++ main.go | 3 +++ 2 files changed, 19 insertions(+) create mode 100644 env/checks.go diff --git a/env/checks.go b/env/checks.go new file mode 100644 index 0000000..cd46d96 --- /dev/null +++ b/env/checks.go @@ -0,0 +1,16 @@ +package env + +import ( + "fmt" + "os" +) + +func RunChecks() { + checkEnv("APP_URL") +} + +func checkEnv(key string) { + if os.Getenv(key) == "" { + panic(fmt.Sprintf("Environment variable %s is not set", key)) + } +} diff --git a/main.go b/main.go index d90dbea..0568ba2 100644 --- a/main.go +++ b/main.go @@ -1,6 +1,7 @@ package main import ( + "anonymousoverflow/env" "anonymousoverflow/src/middleware" "anonymousoverflow/src/routes" "fmt" @@ -11,6 +12,8 @@ import ( func main() { + env.RunChecks() + host := os.Getenv("HOST") if host == "" { host = "0.0.0.0"