Documentation
¶
Overview ¶
Package env provides typed helpers for reading configuration from environment variables with defaults. An unset or empty variable — or one that fails to parse — yields the provided default.
Example ¶
Each reader takes the default inline, so configuration reads as one expression rather than a lookup followed by a zero-value check.
package main
import (
"fmt"
"os"
"time"
"github.com/dobrevit/svckit/env"
)
func main() {
os.Setenv("PORT", "9000")
os.Setenv("FEATURE_ENABLED", "true")
defer func() {
os.Unsetenv("PORT")
os.Unsetenv("FEATURE_ENABLED")
}()
fmt.Println(env.String("PORT", "8080"))
fmt.Println(env.Bool("FEATURE_ENABLED", false))
fmt.Println(env.Duration("SHUTDOWN_GRACE", 30*time.Second))
}
Output: 9000 true 30s
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Bool ¶
Bool returns the variable parsed as a bool ("1", "t", "true", "0", "false", ...), or def when unset or unparsable.
func Duration ¶
Duration returns the variable parsed with time.ParseDuration ("30s", "5m"), or def when unset or unparsable.
Types ¶
This section is empty.
Click to show internal directories.
Click to hide internal directories.