env

package
v4.35.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 24, 2026 License: MIT Imports: 7 Imported by: 890

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Get

func Get(names ...string) (map[string]string, error)

Get environment variables.

func GetOneWithFallback added in v4.15.0

func GetOneWithFallback[T any](main string, defaultValue T, fn func(string) (T, error), names ...string) T

func GetOrDefaultBool

func GetOrDefaultBool(envVar string, defaultValue bool) bool

GetOrDefaultBool returns the given environment variable value as a boolean. Returns the default if the env var cannot be coopered to a boolean, or is not found.

func GetOrDefaultInt

func GetOrDefaultInt(envVar string, defaultValue int) int

GetOrDefaultInt returns the given environment variable value as an integer. Returns the default if the env var cannot be coopered to an int, or is not found.

func GetOrDefaultSecond

func GetOrDefaultSecond(envVar string, defaultValue time.Duration) time.Duration

GetOrDefaultSecond returns the given environment variable value as a time.Duration (second). Returns the default if the env var cannot be coopered to an int, or is not found.

func GetOrDefaultString

func GetOrDefaultString(envVar, defaultValue string) string

GetOrDefaultString returns the given environment variable value as a string. Returns the default if the env var cannot be found.

func GetOrFile

func GetOrFile(envVar string) string

GetOrFile Attempts to resolve 'key' as an environment variable. Failing that, it will check to see if '<key>_FILE' exists. If so, it will attempt to read from the referenced file to populate a value.

func GetWithFallback

func GetWithFallback(groups ...[]string) (map[string]string, error)

GetWithFallback Get environment variable values. The first name in each group is use as key in the result map.

case 1:

// LEGO_ONE="ONE"
// LEGO_TWO="TWO"
env.GetWithFallback([]string{"LEGO_ONE", "LEGO_TWO"})
// => "LEGO_ONE" = "ONE"

case 2:

// LEGO_ONE=""
// LEGO_TWO="TWO"
env.GetWithFallback([]string{"LEGO_ONE", "LEGO_TWO"})
// => "LEGO_ONE" = "TWO"

case 3:

// LEGO_ONE=""
// LEGO_TWO=""
env.GetWithFallback([]string{"LEGO_ONE", "LEGO_TWO"})
// => error

func ParsePairs added in v4.25.0

func ParsePairs(raw string) (map[string]string, error)

ParsePairs parses a raw string of comma-separated key-value pairs into a map. Keys and values are separated by a colon and are trimmed of whitespace.

func ParseSecond added in v4.15.0

func ParseSecond(s string) (time.Duration, error)

ParseSecond parses env var value (string) to a second (time.Duration).

func ParseString added in v4.15.0

func ParseString(s string) (string, error)

ParseString parses env var value (string) to a string but throws an error when the string is empty.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL