summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPatrick Spek <p.spek@tyil.nl>2025-12-02 12:47:28 +0100
committerPatrick Spek <p.spek@tyil.nl>2025-12-02 12:47:28 +0100
commit134a8e7967e49e6a7c383e2e003de48996aa108a (patch)
treeb16f58921c4d6206fca60252ce3cd026987d1b49
downloadenv-134a8e7967e49e6a7c383e2e003de48996aa108a.tar.gz
env-134a8e7967e49e6a7c383e2e003de48996aa108a.tar.bz2
Initial commit
-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