Documentation ¶
Index ¶
- type Config
- type INIConfig
- type JSONConfig
- type Option
- func (opt *Option) GetBool() bool
- func (opt *Option) GetBytes() []byte
- func (opt *Option) GetFloat() float64
- func (opt *Option) GetInt() int64
- func (opt *Option) GetInts(separator string) []int
- func (opt *Option) GetString() string
- func (opt *Option) GetStrings(separator string) []string
- func (opt *Option) GetStructured() interface{}
- type Parameter
- type Section
- type Validator
- type WithConfigBase
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type INIConfig ¶
type INIConfig struct {
WithConfigBase
}
INIConfig holds complete configuration data and metadata for configuration saved as INI file.
func NewINIConfig ¶
NewINIConfig creates and initializes new INIConfig object according to given metadata
type JSONConfig ¶
type JSONConfig struct { WithConfigBase // contains filtered or unexported fields }
JSONConfig holds complete configuration data and metadata for configuration saved as JSON file.
func NewJSONConfig ¶
func NewJSONConfig(metadata map[string][]Parameter, logger *logging.Logger) *JSONConfig
NewJSONConfig creates and initializes new config object according to given metadata.
func (*JSONConfig) AddStructured ¶
func (conf *JSONConfig) AddStructured(section, name, tag string, object interface{})
AddStructured can be used when config values are structured deeper than section/parameter. Note that structured parameters are missing validation logic other than through standard json module (can be changed in future)
func (JSONConfig) GetOption ¶
func (conf JSONConfig) GetOption(name string) (*Option, error)
GetOption returns Option objects according to given "section.option[.sub-option[.sub-option]]" string.
func (JSONConfig) Parse ¶
func (conf JSONConfig) Parse(path string) error
Parse loads data from given file
func (JSONConfig) ParseBytes ¶
func (conf JSONConfig) ParseBytes(data []byte) error
Parse loads data from given byte slice
type Option ¶
type Option struct {
// contains filtered or unexported fields
}
Option holds single value of single configuration option.
func (*Option) GetInts ¶
GetInts returns option value as slice of ints. Use this for value in form of <separator> separated list of ints.
func (*Option) GetStrings ¶
GetStrings returns option value as slice of strings. Use this for value in form of <separator> separated list of strings.
func (*Option) GetStructured ¶
func (opt *Option) GetStructured() interface{}
type Validator ¶
type Validator func(interface{}) (interface{}, error)
Validator checks the validity of the config option value. It accepts single value and returns nil (and corrected value if possible) if the value is valid or appropriate error otherwise.
func BoolValidatorFactory ¶
func BoolValidatorFactory() Validator
BoolValidatorFactory creates validator for checking if the validator's given value is bool.
func IntValidatorFactory ¶
func IntValidatorFactory() Validator
IntValidatorFactory creates validator for checking if the validator's given value is int.
func MultiIntValidatorFactory ¶
MultiIntValidatorFactory creates validator for checking if the validator's given value is list of ints separated by given separator
func StringOptionsValidatorFactory ¶
StringOptionsValidatorFactory creates validator for checking if the validator's given value is one of the factory's given string options.
type WithConfigBase ¶
type WithConfigBase struct { Sections map[string]*Section // contains filtered or unexported fields }
WithConfigBase holds config metadata and logger
func (*WithConfigBase) GetMetadata ¶
func (base *WithConfigBase) GetMetadata() map[string][]Parameter
GetMetadata returns config metadata