Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Enviro ¶
type Enviro struct {
// contains filtered or unexported fields
}
Enviro facilitates the loading and parsing of environment variables into Go structs. It supports custom prefixes for environment variables, nested struct parsing, and fields of various types.
func (*Enviro) MustParseEnv ¶ added in v0.3.0
MustParseEnv is a convenience method that calls ParseEnv and panics if an error occurs.
func (*Enviro) ParseEnv ¶
ParseEnv is a convenience method that calls ParseEnvWithPrefix with the base prefix set on the Enviro instance.
func (*Enviro) ParseEnvWithPrefix ¶
ParseEnvWithPrefix parses environment variables into the provided struct based on struct tags. It uses the specified prefix to look up environment variables, allowing for nested struct parsing and the application of custom parsing logic for specific fields. The function returns an error if parsing fails for any field, or if the provided `config` is not a pointer to a struct.
The `config` parameter should be a pointer to the struct you wish to populate with environment variable values. If the struct contains nested structs and the tag `enviro:"nested:your_prefix"`, the prefix is concatenated with "_" and the nested struct's tag to form the complete environment variable name.
func (*Enviro) SetEnvPrefix ¶
SetEnvPrefix sets a custom prefix that will be prepended to all environment variable names when parsing. Fields with the `enviro:your_var_name,omitprefix` will ignore the prefix.
type ParseField ¶
type ParseField interface {
// ParseField parses the provided string value and sets the receiver accordingly.
// It returns an error if the value cannot be parsed into the expected type.
ParseField(value string) error
}
ParseField is an interface that defines how to parse environment variable values. Types that implement ParseField can define their own logic to parse the string representation of an environment variable into the appropriate Go type.