diff options
author | Andinus <andinus@nand.sh> | 2020-04-06 22:11:15 +0530 |
---|---|---|
committer | Andinus <andinus@nand.sh> | 2020-04-06 22:11:15 +0530 |
commit | da2255557fa395eeabeff9a4f2949582f8811980 (patch) | |
tree | c48de12ff76b54f67303585190773e6551609f1d /cmd/grus/env.go | |
parent | 69e919cd4e887a606dc1c007c2ce1f36b35477d1 (diff) | |
download | grus-da2255557fa395eeabeff9a4f2949582f8811980.tar.gz |
Initial grus version
Diffstat (limited to 'cmd/grus/env.go')
-rw-r--r-- | cmd/grus/env.go | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/cmd/grus/env.go b/cmd/grus/env.go new file mode 100644 index 0000000..4d72030 --- /dev/null +++ b/cmd/grus/env.go @@ -0,0 +1,17 @@ +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. + value, exists := os.LookupEnv(key) + if !exists { + value = fallback + } + return value +} |