env

package
v0.0.0-...-94dd193 Latest Latest
Warning

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

Go to latest
Published: Apr 11, 2024 License: MIT Imports: 4 Imported by: 7

Documentation

Overview

Package env provides utility functions for loading environment variables with defaults.

A common use of the env package is for combining flag with environment variables in a Go program.

Example:

func main() {
	var (
		flProject = flag.String("http.addr", env.String("HTTP_ADDRESS", ":https"), "HTTP server address")
	)
	flag.Parse()
}

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Bool

func Bool(key string, def bool) bool

Bool returns the environment variable value specified by the key parameter (parsed as a boolean), otherwise returning a default value if set.

func Duration

func Duration(key string, def time.Duration) time.Duration

Duration returns the environment variable value specified by the key parameter, otherwise returning a default value if set. If the time.Duration value cannot be parsed, Duration will exit the program with an error status.

func Int

func Int(key string, def int) int

Int returns the environment variable value specified by the key parameter, parsed as an integer. If the environment variable is not set, the default value is returned. If parsing the integer fails, Int will exit the program.

func String

func String(key, def string) string

String returns the environment variable value specified by the key parameter, otherwise returning a default value if set.

Types

This section is empty.

Jump to

Keyboard shortcuts

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