Documentation
¶
Overview ¶
Package config provides typed accessors for environment variables with sensible defaults and panic-on-missing semantics.
For .env file loading, use the godotenv/autoload blank import in your main package:
import _ "github.com/joho/godotenv/autoload"
Index ¶
- func GetEnvCSV(key string) []string
- func GetEnvOrDefault(key, def string) string
- func GetEnvOrDefaultBool(key string, def bool) bool
- func GetEnvOrDefaultDuration(key string, def time.Duration) time.Duration
- func GetEnvOrDefaultInt(key string, def int) int
- func GetEnvOrPanic(key string) string
- func ParseBaseURL(raw string) (origin, hostname string, err error)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func GetEnvCSV ¶
GetEnvCSV returns the environment variable named by key parsed as a comma-separated list, with surrounding whitespace trimmed and empty entries dropped. Returns nil when the variable is unset/empty or contains no non-empty entries.
func GetEnvOrDefault ¶
GetEnvOrDefault returns the value of the environment variable named by key, or def if the variable is unset or empty.
func GetEnvOrDefaultBool ¶
GetEnvOrDefaultBool returns the environment variable as a bool, falling back to def if unset, empty, or not a valid boolean. Note: invalid values silently fall back to the default with no warning.
func GetEnvOrDefaultDuration ¶
GetEnvOrDefaultDuration returns the environment variable as a time.Duration, falling back to def if unset, empty, or not a valid duration string. Note: invalid values silently fall back to the default with no warning.
func GetEnvOrDefaultInt ¶
GetEnvOrDefaultInt returns the environment variable as an int, falling back to def if unset, empty, or not a valid integer. Note: invalid values silently fall back to the default with no warning.
func GetEnvOrPanic ¶
GetEnvOrPanic returns the value of the environment variable named by key. It panics if the variable is unset or empty.
func ParseBaseURL ¶
ParseBaseURL validates a raw base URL string and returns the origin (scheme://host, including port if present) and the hostname (without port). An empty input is valid and returns zero values (optional in dev).
Types ¶
This section is empty.