Documentation
¶
Overview ¶
Package env contains functions to interact with environment variables.
The package is imported like this:
import "github.com/gouniverse/base/env"
Index ¶
- func Bool(key string) bool
- func BoolDefault(key string, defaultValue bool) bool
- func Initialize(envFilePath ...string)
- func Must(key string) string
- func Value(key string) string
- func ValueOrDefault(key string, defaultValue string) string
- func ValueOrError(key string) (string, error)
- func ValueOrPanic(key string) string
- func VaultLoad(options struct{ ... }) error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Bool ¶ added in v0.2.0
Bool returns the value for an environment key
Any of the following values are considered true: "true", "True", "TRUE", "T", "t", "1" Any of the following values are considered false: "false", "False", "FALSE", "F", "f", "0" Any other value returns the default false.
Parameters:
- key: The environment key
Returns:
- The value for the environment key, false if not set
func BoolDefault ¶ added in v0.2.0
BoolDefault returns the value for an environment key with a default value
Any of the following values are considered true: "true", "True", "TRUE", "T", "t", "1" Any of the following values are considered false: "false", "False", "FALSE", "F", "f", "0" Any other value returns the default value.
Parameters:
- key: The environment key
- defaultValue: The default value
Returns:
- The value for the environment key
func Initialize ¶
func Initialize(envFilePath ...string)
Initialize initializes the environment variables
Business logic: - Loads .env file (by default, no need to provide path) - Loads env files from the provided paths, if any
Parameters: - envFilePath: slice of strings representing the paths to the .env files to load
Returns: - None
func Value ¶
Value returns the value for an environment key
If the value is not found, or if the value cannot be processed, returns an empty string.
If you want a default value, use ValueOrDefault. If you want an error, use ValueOrError. If you want a panic, use ValueOrPanic.
Parameters:
- key: The environment key
Returns:
- The value for the environment key
func ValueOrDefault ¶ added in v0.2.0
ValueOr returns the value for an environment key with a default value
Parameters:
- key: The environment key
- defaultValue: The default value
Returns:
- The value for the environment key
func ValueOrError ¶ added in v0.2.0
func ValueOrPanic ¶ added in v0.2.0
Types ¶
This section is empty.