Documentation
¶
Overview ¶
Package env provides functions for loading and parsing configuration files in the '.env' format.
The '.env' format is a simple key-value format, with one key-value pair per line. Lines that begin with a '#' character are treated as comments and are ignored. Keys and values may be surrounded by quotes, but this is not required.
The LoadConfig function can be used to load a configuration file and parse its key-value pairs into a struct or map. Converter functions can be provided to specify how each key's value should be parsed.
The LoadEnv function can be used to load a configuration file and set the corresponding environment variables for the current process.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func LoadConfig ¶
The config struct is passed as an argument and the LoadConfig function uses reflection to examine the fields of the struct and compare the key name with the "name" tag. If a match is found, it uses a switch statement to check the field's Kind and parse the value accordingly. If the fields are not primitive types or the key is not found in the struct, it returns an error.
func LoadEnv ¶
LoadEnv loads the key-value pairs from a configuration file in the '.env' format and sets the corresponding environment variables for the current process. If a key is already set in the environment, it is overwritten. Lines that begin with a '#' character are treated as comments and are ignored. Keys and values may be surrounded by quotes, but this is not required.
If the file does not exist or cannot be read, an error is returned.
Types ¶
type KeyValuePair ¶
KeyValuePair represents a key-value pair in an '.env' file.