summaryrefslogtreecommitdiff
path: root/env.go
diff options
context:
space:
mode:
Diffstat (limited to 'env.go')
-rw-r--r--env.go31
1 files changed, 31 insertions, 0 deletions
diff --git a/env.go b/env.go
new file mode 100644
index 0000000..234087b
--- /dev/null
+++ b/env.go
@@ -0,0 +1,31 @@
+package env
+
+import (
+ "os"
+ "strconv"
+)
+
+func String(name string, fallback string) string {
+ value, ok := os.LookupEnv(name)
+
+ if ok {
+ return value
+ }
+
+ return fallback
+}
+
+func Int(name string, fallback int) int {
+ value, ok := os.LookupEnv(name)
+
+ if ok {
+ value, err := strconv.Atoi(value)
+ if err != nil {
+ return 0
+ }
+
+ return value
+ }
+
+ return fallback
+}