Documentation ¶
Overview ¶
Package env loads configuration from environment variables.
Env loads environment variables whose names starts with the given prefix and returns them as a nested map[string]any. Environment variables with empty values are treated as unset.
It splits the names by delimiter. For example, with the default delimiter "_", the environment variable `PARENT_CHILD_KEY="1"` is loaded as `{PARENT: {CHILD: {KEY: "1"}}}`.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Env ¶
type Env struct {
// contains filtered or unexported fields
}
Env is a Provider that loads configuration from environment variables.
To create a new Env, call New.
type Option ¶
type Option func(*options)
Option configures an Env with specific options.
func WithNameSplitter ¶ added in v0.5.0
WithNameSplitter provides the function used to split environment variable names into nested keys. If it returns an nil/[]string{}/[]string{""}, the variable will be ignored.
For example, with the default splitter, an environment variable name like "PARENT_CHILD_KEY" would be split into "PARENT", "CHILD", and "KEY".
func WithPrefix ¶
WithPrefix provides the prefix used when loading environment variables. Only environment variables with names that start with the prefix will be loaded.
For example, if the prefix is "server", only environment variables whose names start with "server" will be loaded. By default, it has no prefix which loads all environment variables.