Documentation
¶
Overview ¶
Package conf provides functionality to read configuration files of any format.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Config ¶
type Config map[string]interface{}
Config represents a container for all parsed configuration values.
func Load ¶
func Load(r io.Reader, unmarshal Unmarshaler) (Config, error)
Load loads the configuration from the source r using unmarshal to parse the input stream. The returned Config object holds all parsed values.
func MustLoad ¶
func MustLoad(r io.Reader, unmarshal Unmarshaler) Config
MustLoad ensures the loading of the configuration from the r using unmarshal to parse the input stream. This function calls Load and panics on error.
func (Config) Decode ¶
Decode stores the configuration value with the given key in value. If value has an invalid type an error is returned. Decode tries to convert the configuration value to value's type (e.g. the string "7" is converted to the integer 7). The given value has to be a pointer, otherwise an error is returned.
When decoding a struct each field could provide a 'config' tag. If the tag is "-" the field will be ignored. Otherwise it consists of a custom configuration key, followed by an optional comma and options. If the custom configuration key is empty the field name will be used. Currently only "required" is a valid option. If the "required" option will be set and the key does not exist an error is returned.
Tag examples:
// Field will be ignored Field string `config:"-"` // Field is required, the key is "Field" Field string `config:",required"` // Field is optional, the key is "foobar" Field string `config:"foobar"` // Field is required, the key is "foobar" Field string `config:"foobar,required"`
type Unmarshaler ¶
Unmarshaler represents a function which is able to parse the configuration data and store the parsed values into the given value.
type Value ¶
Value represents a specific configuration value which can be converted to several types.
func (*Value) Bool ¶
Bool tries to convert the configuration value to a boolean value. If the conversion fails an error is returned.
func (*Value) Float ¶
Float tries to convert the configuration value to a floating point value. If the conversion fails an error is returned.
func (*Value) Int ¶
Int tries to convert the configuration value to an integer value. If the conversion fails an error is returned.
