Skip to content
/ env Public

A small utility package to load different types of environment variables.

License

Notifications You must be signed in to change notification settings

maragudk/env

Repository files navigation

env

GoDoc Go

A small utility package to load different types of environment variables.

Made in 🇩🇰 by maragu, maker of online Go courses.

Usage

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)
}