conf
YAML Configuration Reader
Note
All configurations files used by the conf package should be located under /usr/local/conf unless you change that folder in the conf.go source file.
Usage
Import the Trulioo/conf package into your go source.
After the program initialisation, a Conf variable will be created that holds your configuration. The configuration itself will be loaded from a YAML file with the name of your program, followed by "-" and the value of the -env parameter passed to it (by default "local"), and with a suffix of ".yml".
E.g. if your program is called program and you want to run in a production environment, then you would start it using ./program -env=prod and your configuration file should be named program-prod.yml and located under /usr/local/conf
In your program, if you need to access any configuration element, first save the configuration in a variable, using conf.GetConf().
You can get access to any element in the configuration using its path. You will use FindNode(conf.Conf,"element.subelement") for that purpose. FindNode returns an interface{} and an error.
If you want to save yourself the hard work dealing with interface{} elements, you can use 3 helpers:
- GetString(path string) (string,error) will return the string located at path
- GetList(interface{}) ([]yaml.Node,error) will return you an array of Yaml Nodes (not necessarily better to deal with)
- GetStringsMap(path string) (map[string]string,error) will return you a map of string elements corresponding to the path informed.