Documentation ¶
Index ¶
- Variables
- type Cfg
- func (c *Cfg) Bool(key string) (bool, bool)
- func (c *Cfg) BoolOr(key string, defaultVal bool) bool
- func (c *Cfg) Bools() map[string]bool
- func (c *Cfg) Debug()
- func (c *Cfg) Float(key string) (float64, bool)
- func (c *Cfg) FloatOr(key string, defaultVal float64) float64
- func (c *Cfg) Floats() map[string]float64
- func (c *Cfg) GrabBool(key string) bool
- func (c *Cfg) GrabFloat(key string) float64
- func (c *Cfg) GrabInt(key string) int
- func (c *Cfg) GrabMap(key string) interface{}
- func (c *Cfg) GrabSlice(key string) interface{}
- func (c *Cfg) GrabString(key string) string
- func (c *Cfg) GrabStruct(key string) interface{}
- func (c *Cfg) Int(key string) (int, bool)
- func (c *Cfg) IntOr(key string, defaultVal int) int
- func (c *Cfg) Ints() map[string]int
- func (c *Cfg) JSON() (string, error)
- func (c *Cfg) Load(pvds ...CfgProvider) (*Cfg, error)
- func (c *Cfg) Map(key string) (interface{}, bool)
- func (c *Cfg) MapOr(key string, defaultVal interface{}) interface{}
- func (c *Cfg) Maps() map[string]interface{}
- func (c *Cfg) Print()
- func (c *Cfg) SetBool(key string, val bool)
- func (c *Cfg) SetFloat(key string, val float64)
- func (c *Cfg) SetInt(key string, val int)
- func (c *Cfg) SetMap(key string, val interface{})
- func (c *Cfg) SetSlice(key string, val interface{})
- func (c *Cfg) SetString(key string, val string)
- func (c *Cfg) SetStruct(key string, val interface{})
- func (c *Cfg) Slice(key string) (interface{}, bool)
- func (c *Cfg) SliceOr(key string, defaultVal interface{}) interface{}
- func (c *Cfg) Slices() map[string]interface{}
- func (c *Cfg) String(key string) (string, bool)
- func (c *Cfg) StringOr(key string, defaultVal string) string
- func (c *Cfg) Strings() map[string]string
- func (c *Cfg) Struct(key string) (interface{}, bool)
- func (c *Cfg) StructOr(key string, defaultVal interface{}) interface{}
- func (c *Cfg) Structs() map[string]interface{}
- func (c *Cfg) Template() interface{}
- func (c *Cfg) ToString() string
- type CfgProvider
- type GoCfgCfg
- type ICfg
- type JSONCfg
- type JSONStrCfg
- type YAMLCfg
- type YAMLStrCfg
Constants ¶
This section is empty.
Variables ¶
var GocfgTag = "cfg"
var GocfgValEnv = "env"
var GocfgValRequired = "required"
Functions ¶
This section is empty.
Types ¶
type Cfg ¶
type Cfg struct {
// contains filtered or unexported fields
}
Cfg is an abstraction over a configuration
func (*Cfg) Bool ¶
Bool get a configuration value according to key, the second returned value is false if nothing not found.
func (*Cfg) BoolOr ¶
BoolOr get a configuration value according to the key, or it returns the defaultVal instead.
func (*Cfg) Float ¶
Float get a configuration value according to key, the second returned value is false if nothing not found.
func (*Cfg) FloatOr ¶
FloatOr get a configuration value according to the key, or it returns the defaultVal instead.
func (*Cfg) GrabBool ¶
GrabBool get a configuration value according to the key, it returns zero value if no value is found.
func (*Cfg) GrabFloat ¶
GrabFloat get a configuration value according to the key, it returns zero value if no value is found.
func (*Cfg) GrabInt ¶
GrabInt get a configuration value according to the key, it returns zero value if no value is found.
func (*Cfg) GrabMap ¶
GrabMap get a configuration value according to the key, it returns zero value if no value is found.
func (*Cfg) GrabSlice ¶
GrabSlice get a configuration value according to the key, it returns zero value if no value is found.
func (*Cfg) GrabString ¶
GrabString get a configuration value according to the key, it returns zero value if no value is found.
func (*Cfg) GrabStruct ¶
GrabStruct get a configuration value according to the key, it returns zero value if no value is found.
func (*Cfg) Int ¶
Int get a configuration value according to key, the second returned value is false if nothing not found.
func (*Cfg) IntOr ¶
IntOr get a configuration value according to the key, or it returns the defaultVal instead.
func (*Cfg) Load ¶
func (c *Cfg) Load(pvds ...CfgProvider) (*Cfg, error)
Load loads configuration from local path according to config's definition
func (*Cfg) Map ¶
Map get a configuration value according to key, the second returned value is false if nothing not found.
func (*Cfg) MapOr ¶
MapOr get a configuration value according to the key, or it returns the defaultVal instead.
func (*Cfg) Slice ¶
Slice get a configuration value according to key, the second returned value is false if nothing not found.
func (*Cfg) SliceOr ¶
SliceOr get a configuration value according to the key, or it returns the defaultVal instead.
func (*Cfg) String ¶
String get a configuration value according to key, the second returned value is false if nothing not found.
func (*Cfg) StringOr ¶
StringOr get a configuration value according to the key, or it returns the defaultVal instead.
func (*Cfg) Struct ¶
Struct get a configuration value according to key, the second returned value is false if nothing not found.
func (*Cfg) StructOr ¶
StructOr get a configuration value according to the key, or it returns the defaultVal instead.
type CfgProvider ¶
type CfgProvider interface {
Load(dstCfg interface{}) error
}
CfgProvider is a configuration loader interface
type GoCfgCfg ¶
type GoCfgCfg struct {
// contains filtered or unexported fields
}
GoCfgCfg is a configuration loader for a gocfg struct
type ICfg ¶
type ICfg interface { Bool(key string) (bool, bool) Int(key string) (int, bool) Float(key string) (float64, bool) String(key string) (string, bool) Map(key string) (interface{}, bool) Slice(key string) (interface{}, bool) Struct(key string) (interface{}, bool) BoolOr(key string, defaultVal bool) bool IntOr(key string, defaultVal int) int FloatOr(key string, defaultVal float64) float64 StringOr(key string, defaultVal string) string MapOr(key string, defaultVal interface{}) interface{} SliceOr(key string, defaultVal interface{}) interface{} StructOr(key string, defaultVal interface{}) interface{} GrabBool(key string) bool GrabInt(key string) int GrabFloat(key string) float64 GrabString(key string) string GrabMap(key string) interface{} GrabSlice(key string) interface{} GrabStruct(key string) interface{} Bools() map[string]bool Ints() map[string]int Floats() map[string]float64 Strings() map[string]string Maps() map[string]interface{} Slices() map[string]interface{} Structs() map[string]interface{} SetBool(key string, val bool) SetInt(key string, val int) SetFloat(key string, val float64) SetString(key string, val string) SetStruct(key string, val interface{}) Print() Debug() ToString() string JSON() (string, error) Template() interface{} }
ICfg is an interface defined for consumer according to *gocfg.Cfg
type JSONCfg ¶
type JSONCfg struct {
// contains filtered or unexported fields
}
JSONCfg is a configuration loader for a local json file
type JSONStrCfg ¶
type JSONStrCfg struct {
// contains filtered or unexported fields
}
JSONStrCfg is a configuration loader for a json string
func JSONStr ¶
func JSONStr(content string) *JSONStrCfg
JSONStr inits a JSONStrCfg according to the content
func (*JSONStrCfg) Load ¶
func (cfg *JSONStrCfg) Load(dstCfg interface{}) error
Load populates content according to the definition of the dstCfg
type YAMLCfg ¶
type YAMLCfg struct {
// contains filtered or unexported fields
}
YAMLCfg is a configuration loader for a local yaml file
type YAMLStrCfg ¶
type YAMLStrCfg struct {
// contains filtered or unexported fields
}
YAMLStrCfg is a configuration loader for a local yaml file
func YAMLStr ¶
func YAMLStr(content string) *YAMLStrCfg
YAMLStr inits a YAMLStrCfg according to the json file in the path
func (*YAMLStrCfg) Load ¶
func (cfg *YAMLStrCfg) Load(dstCfg interface{}) error
Load populates yaml file according to the definition of the dstCfg