Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ErrNoConfigFound ¶
type ErrNoConfigFound struct{}
ErrNoConfigFound returned by ReloadConfig if no config file cound be found
func (ErrNoConfigFound) Error ¶
func (ErrNoConfigFound) Error() string
type Manager ¶
type Manager struct { Conf interface{} // contains filtered or unexported fields }
Manager is in charge of finding and reading configuration files
func New ¶
func New( defaultConf, confDir, fileName string, config interface{}, autoload bool, ) (*Manager, error)
New prepares a new configuration manager which can be used to read properties from a TOML config file. The confDir param can be used to set a custom config directory. If it's left empty the default config locations will be used. When no config files can be found on the system a new one will be generated in the current working directory, and the program will exit. If it fails to write the config file it will print instructions for the user to create a new config file and exit with an error status.
Params:
- defaultConfig: The default configuration file in TOML format. If a config file is found at any of the configured locations, but it's missing some tags the default values from this config will be used. Note that if no config files are found, all the properties will be the defaults.
- confDir: A directory which will be searched for a configuration file. If empty the default system directories will be searched for configuration files.
- fileName: The name of the configuration file, only files with this name will be attempted to be parsed.
- conf: This has to be a pointer to a struct with TOML annotations. https://github.com/BurntSushi/toml/blob/master/README.md#examples
- autoload: Setting this to true will automatically load the config file before returning this function. If it fails to load the config file it will print instructions for the user to stdout and exit the program. If you wish to handle this behaviour yourself you should set autoload to false and call Manager.LoadConfig manually.
func (*Manager) LoadConfig ¶
LoadConfig tries every configuration file configured in the Manager until it finds one it can read. If no configuration files can be read it will return an ErrNoConfigFound error. If error is nil the config was loaded successfully. This function can be called multiple times to reload the config file from disk.