Documentation
¶
Overview ¶
Package gonfig implements methods for reading config files encoded in json using path expressions and default fallback values
Index ¶
- type Gonfig
- type JsonGonfig
- func (jgonfig *JsonGonfig) Get(key string, defaultValue interface{}) (interface{}, error)
- func (jgonfig *JsonGonfig) GetAs(key string, target interface{}) error
- func (jgonfig *JsonGonfig) GetBool(key string, defaultValue interface{}) (bool, error)
- func (jgonfig *JsonGonfig) GetFloat(key string, defaultValue interface{}) (float64, error)
- func (jgonfig *JsonGonfig) GetInt(key string, defaultValue interface{}) (int, error)
- func (jgonfig *JsonGonfig) GetString(key string, defaultValue interface{}) (string, error)
- type KeyNotFoundError
- type UnexpectedValueTypeError
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Gonfig ¶
type Gonfig interface { Get(key string, defaultValue interface{}) (interface{}, error) GetString(key string, defaultValue interface{}) (string, error) GetInt(key string, defaultValue interface{}) (int, error) GetFloat(key string, defaultValue interface{}) (float64, error) GetBool(key string, defaultValue interface{}) (bool, error) GetAs(key string, target interface{}) error }
func FromJson ¶
FromJson reads the contents from the supplied reader. The content is parsed as json into a map[string]interface{}. It returns a JsonGonfig struct pointer and any error encountered
func FromJsonFile ¶
FromJsonFile opens the file supplied and calls FromJson function
type JsonGonfig ¶
type JsonGonfig struct {
// contains filtered or unexported fields
}
Gonfig implementation Implements the Gonfig interface
func (*JsonGonfig) Get ¶
func (jgonfig *JsonGonfig) Get(key string, defaultValue interface{}) (interface{}, error)
Get attempts to retreive the value behind the supplied key. It returns a interface{} with either the retreived value or the default value and any error encountered. If supplied key is not found and defaultValue is set to nil it returns a KeyNotFoundError If supplied key path goes deeper into a non-map type (string, int, bool) it returns a UnexpectedValueTypeError
func (*JsonGonfig) GetAs ¶
func (jgonfig *JsonGonfig) GetAs(key string, target interface{}) error
GetAs uses Get to fetch the value behind the supplied key. The value is serialized into json and deserialized into the supplied target interface. It returns any error encountered.
func (*JsonGonfig) GetBool ¶
func (jgonfig *JsonGonfig) GetBool(key string, defaultValue interface{}) (bool, error)
GetBool uses Get to fetch the value behind the supplied key. It returns a bool with either the retreived value or the default value and any error encountered. If value is not a bool it returns a UnexpectedValueTypeError
func (*JsonGonfig) GetFloat ¶
func (jgonfig *JsonGonfig) GetFloat(key string, defaultValue interface{}) (float64, error)
GetFloat uses Get to fetch the value behind the supplied key. It returns a float with either the retreived value or the default value and any error encountered. It returns a bool with either the retreived value or the default value and any error encountered. If value is not a float it returns a UnexpectedValueTypeError
func (*JsonGonfig) GetInt ¶
func (jgonfig *JsonGonfig) GetInt(key string, defaultValue interface{}) (int, error)
GetInt uses Get to fetch the value behind the supplied key. It returns a int with either the retreived value or the default value and any error encountered. If value is not a int it returns a UnexpectedValueTypeError
func (*JsonGonfig) GetString ¶
func (jgonfig *JsonGonfig) GetString(key string, defaultValue interface{}) (string, error)
GetString uses Get to fetch the value behind the supplied key. It returns a string with either the retreived value or the default value and any error encountered. If value is not a string it returns a UnexpectedValueTypeError
type KeyNotFoundError ¶
type KeyNotFoundError struct {
// contains filtered or unexported fields
}
func (*KeyNotFoundError) Error ¶
func (err *KeyNotFoundError) Error() string
type UnexpectedValueTypeError ¶
type UnexpectedValueTypeError struct {
// contains filtered or unexported fields
}
func (*UnexpectedValueTypeError) Error ¶
func (err *UnexpectedValueTypeError) Error() string