summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--env.go31
-rw-r--r--go.mod3
2 files changed, 34 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
+}
diff --git a/go.mod b/go.mod
new file mode 100644
index 0000000..0f22d50
--- /dev/null
+++ b/go.mod
@@ -0,0 +1,3 @@
+module git.tyil.nl/go/env.git
+
+go 1.25.3