Documentation
¶
Overview ¶
Package env reads configuration from environment variables.
Get is the entry point: it parses the variable into the type of the default value it is given, and returns that default when the variable is unset or cannot be parsed.
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Get ¶
Get retrieves an environment variable and parses it to the type of the default value. If the value is not set or cannot be parsed, the default value is returned. Supported types: bool, int, float64, string, time.Duration
Example ¶
package main
import (
"fmt"
"os"
"time"
"github.com/andygeiss/cloud-native-utils/env"
)
func main() {
_ = os.Setenv("PORT", "8443")
defer func() { _ = os.Unsetenv("PORT") }()
// The default value decides the type the variable is parsed into.
port := env.Get("PORT", 8080)
// An unset variable yields the default.
timeout := env.Get("SERVER_READ_TIMEOUT", 5*time.Second)
fmt.Println(port)
fmt.Println(timeout)
}
Output: 8443 5s
Types ¶
This section is empty.
Click to show internal directories.
Click to hide internal directories.