From 53d4a70ed2d1db9e7ebb98ec734d414539a74fc8 Mon Sep 17 00:00:00 2001 From: Andinus Date: Fri, 24 Apr 2020 19:52:18 +0530 Subject: Move app func to main --- env.go | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 env.go (limited to 'env.go') diff --git a/env.go b/env.go new file mode 100644 index 0000000..9288c35 --- /dev/null +++ b/env.go @@ -0,0 +1,18 @@ +package main + +import "os" + +// getEnv will check if the the key exists, if it does then it'll +// return the value otherwise it will return fallback string. +func getEnv(key, fallback string) string { + // We use os.LookupEnv instead of using os.GetEnv and checking + // if the length equals 0 because environment variable can be + // set and be of length 0. User could've set key="" which + // means the variable was set but the length is 0. There is no + // reason why user would want to do this over here though. + value, exists := os.LookupEnv(key) + if !exists { + value = fallback + } + return value +} -- cgit 1.4.1-2-gfad0