A small utility package to load different types of environment variables.
Made in 🇩🇰 by maragu, maker of online Go courses.
go get maragu.dev/env
package main
import (
"fmt"
"time"
"maragu.dev/env"
)
func main() {
env.MustLoad()
host := env.GetStringOrDefault("HOST", "localhost")
port := env.GetIntOrDefault("PORT", 8080)
tls := env.GetBoolOrDefault("TLS_ENABLED", false)
shutdownTimeout := env.GetDurationOrDefault("SHUTDOWN_TIMEOUT", time.Minute)
fmt.Println(host, port, tls, shutdownTimeout)
}