diff options
| author | Patrick Spek <p.spek@tyil.nl> | 2025-12-02 12:47:28 +0100 |
|---|---|---|
| committer | Patrick Spek <p.spek@tyil.nl> | 2025-12-02 12:47:28 +0100 |
| commit | 134a8e7967e49e6a7c383e2e003de48996aa108a (patch) | |
| tree | b16f58921c4d6206fca60252ce3cd026987d1b49 | |
| download | env-134a8e7967e49e6a7c383e2e003de48996aa108a.tar.gz env-134a8e7967e49e6a7c383e2e003de48996aa108a.tar.bz2 | |
Initial commit
| -rw-r--r-- | env.go | 31 | ||||
| -rw-r--r-- | go.mod | 3 |
2 files changed, 34 insertions, 0 deletions
@@ -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 +} @@ -0,0 +1,3 @@ +module git.tyil.nl/go/env.git + +go 1.25.3 |
