Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ( // ErrTargetNotPointer is returned if the provided target value is not a pointer. ErrTargetNotPointer = errors.New("target is not pointer") // ErrFileDoesNotExist is returned if the provided file path does not exist. ErrFileDoesNotExist = errors.New("file does not exist") // ErrInvalidConfigFileType is returned if the provided configFileType constant is not a valid type. ErrInvalidConfigFileType = errors.New("invalid config file type") )
Functions ¶
func Parse ¶
func Parse(configFileType ConfigFileType, file string, target interface{}, defaults map[string]interface{}, envPrefix string) error
Parse reads in a configuration file and unmarshals the data into the provided target value. The configFileType argument specifies the type of the configuration file (JSON or YAML). The file argument is the file path of the configuration file. The target argument should be a pointer to the value that the configuration data will be unmarshaled into. The defaults argument is a map of default values that will be set in the configuration if they are not present in the configuration file. The envPrefix argument is a string specifying the environment variables prefix to use when reading env vars (eg. "myPrefix" results in "MYPREFIX_MYPROP") If there is an error reading in the configuration file or unmarshaling the data, an error is returned.
Types ¶
type ConfigFileType ¶
type ConfigFileType uint8
ConfigFileType is a type for constants that represent the type of a configuration file.
const ( // ConfigFileTypeJSON represents a JSON configuration file. ConfigFileTypeJSON ConfigFileType = iota // ConfigFileTypeYAML represents a YAML configuration file. ConfigFileTypeYAML )