Documentation ¶
Index ¶
- Variables
- func DeepCopy(value interface{}) interface{}
- func ParseJSONConfig(data []byte, model interface{}) error
- func ParseXMLConfig(data []byte, model interface{}) error
- func ParseYAMLConfig(data []byte, model interface{}) error
- func ReadJSONFile(filepath string, model interface{}) error
- func ReadXMLFile(name string) ([]byte, error)
- func ReadYAMLFile(name string) ([]byte, error)
- type AdapterConfig
- func (p *AdapterConfig) Copy() Config
- func (p *AdapterConfig) Dump() (bs []byte, err error)
- func (p *AdapterConfig) GetBoolean(key string, defValue ...bool) (b bool)
- func (p *AdapterConfig) GetBooleanList(key string) []bool
- func (p *AdapterConfig) GetByteSize(key string) *big.Int
- func (p *AdapterConfig) GetConfig(key string) Config
- func (p *AdapterConfig) GetFloat(key string, defValue ...float64) (res float64)
- func (p *AdapterConfig) GetFloatList(key string) []float64
- func (p *AdapterConfig) GetInt(key string, defValue ...int) (res int)
- func (p *AdapterConfig) GetIntList(key string) []int
- func (p *AdapterConfig) GetInterface(key string, defValue ...interface{}) (res interface{})
- func (p *AdapterConfig) GetKeyValue(key string) (vm interface{}, err error)
- func (p *AdapterConfig) GetKeys() []string
- func (p *AdapterConfig) GetList(key string) (res []interface{})
- func (p *AdapterConfig) GetMap(key string) Options
- func (p *AdapterConfig) GetString(key string, defValue ...string) (res string)
- func (p *AdapterConfig) GetStringList(key string) []string
- func (p *AdapterConfig) GetTimeDuration(key string, defValue ...time.Duration) time.Duration
- func (p *AdapterConfig) GetValuesConfig(key string) Config
- func (p *AdapterConfig) SetKeyValue(key string, value interface{}) (err error)
- func (p *AdapterConfig) ToObject(key string, model interface{}) error
- type Config
- type OptionFunc
- type Options
- type Reader
- type ReaderOptionFunc
- type ReaderOptions
- type ReaderType
Constants ¶
This section is empty.
Variables ¶
var ( ErrNotMap = errors.New("interface is not a map") ErrValueNil = errors.New("value is nil") ErrInvalidKey = errors.New("invalid key") ErrInvalidFilePath = errors.New("invalid file path") ErrUnknownSuffixes = errors.New("unknown file with suffix") ErrNotSupportedReaderType = errors.New("not supported reader type") )
Errors
Functions ¶
func ParseJSONConfig ¶ added in v1.3.0
ParseJSONConfig 解析Json配置
func ParseXMLConfig ¶ added in v1.3.0
ParseXMLConfig 解析yaml的配置信息
func ParseYAMLConfig ¶ added in v1.3.0
ParseYAMLConfig 解析yaml的配置信息
func ReadJSONFile ¶ added in v1.3.0
ReadJSONFile 读取Json文件数据到Models
func ReadXMLFile ¶ added in v1.3.0
ReadXMLFile 读取yaml文件的配置信息
func ReadYAMLFile ¶ added in v1.3.0
ReadYAMLFile 读取yaml文件的配置信息
Types ¶
type AdapterConfig ¶ added in v1.3.0
type AdapterConfig struct { ConfigFile string ConfigString string ConfigStruct interface{} // contains filtered or unexported fields }
AdapterConfig default config adapter
func (*AdapterConfig) Copy ¶ added in v1.3.0
func (p *AdapterConfig) Copy() Config
Copy return a copy
func (*AdapterConfig) Dump ¶ added in v1.3.0
func (p *AdapterConfig) Dump() (bs []byte, err error)
Dump return p.configs' bytes
func (*AdapterConfig) GetBoolean ¶ added in v1.3.0
func (p *AdapterConfig) GetBoolean(key string, defValue ...bool) (b bool)
GetBoolean return a bool object in p.configs by key
func (*AdapterConfig) GetBooleanList ¶ added in v1.3.0
func (p *AdapterConfig) GetBooleanList(key string) []bool
GetBooleanList return a list of booleans in p.configs by key
func (*AdapterConfig) GetByteSize ¶ added in v1.3.0
func (p *AdapterConfig) GetByteSize(key string) *big.Int
GetByteSize return time in p.configs by key
func (*AdapterConfig) GetConfig ¶ added in v1.3.0
func (p *AdapterConfig) GetConfig(key string) Config
GetConfig return object config in p.configs by key
func (*AdapterConfig) GetFloat ¶ added in v1.3.0
func (p *AdapterConfig) GetFloat(key string, defValue ...float64) (res float64)
GetFloat return a float object in p.configs by key
func (*AdapterConfig) GetFloatList ¶ added in v1.3.0
func (p *AdapterConfig) GetFloatList(key string) []float64
GetFloatList return a list of floats in p.configs by key
func (*AdapterConfig) GetInt ¶ added in v1.3.0
func (p *AdapterConfig) GetInt(key string, defValue ...int) (res int)
GetInt return a int object in p.configs by key
func (*AdapterConfig) GetIntList ¶ added in v1.3.0
func (p *AdapterConfig) GetIntList(key string) []int
GetIntList return a list of ints in p.configs by key
func (*AdapterConfig) GetInterface ¶ added in v1.3.0
func (p *AdapterConfig) GetInterface(key string, defValue ...interface{}) (res interface{})
GetInterface return a interface object in p.configs by key
func (*AdapterConfig) GetKeyValue ¶ added in v1.5.0
func (p *AdapterConfig) GetKeyValue(key string) (vm interface{}, err error)
GetKeyValue get value with key
func (*AdapterConfig) GetKeys ¶ added in v1.3.0
func (p *AdapterConfig) GetKeys() []string
GetKeys get map keys
func (*AdapterConfig) GetList ¶ added in v1.3.0
func (p *AdapterConfig) GetList(key string) (res []interface{})
GetList return a list of interface{} in p.configs by key
func (*AdapterConfig) GetMap ¶ added in v1.3.0
func (p *AdapterConfig) GetMap(key string) Options
GetMap get map value
func (*AdapterConfig) GetString ¶ added in v1.3.0
func (p *AdapterConfig) GetString(key string, defValue ...string) (res string)
GetString return a string object in p.configs by key
func (*AdapterConfig) GetStringList ¶ added in v1.3.0
func (p *AdapterConfig) GetStringList(key string) []string
GetStringList return a list of strings in p.configs by key
func (*AdapterConfig) GetTimeDuration ¶ added in v1.3.0
GetTimeDuration return time in p.configs by key
func (*AdapterConfig) GetValuesConfig ¶ added in v1.3.0
func (p *AdapterConfig) GetValuesConfig(key string) Config
GetValuesConfig get key's values if values can be Config, or panic
func (*AdapterConfig) SetKeyValue ¶ added in v1.3.0
func (p *AdapterConfig) SetKeyValue(key string, value interface{}) (err error)
SetKeyValue set key value into p.configs
func (*AdapterConfig) ToObject ¶ added in v1.5.0
func (p *AdapterConfig) ToObject(key string, model interface{}) error
ToObject unmarshal values to object
type Config ¶
type Config interface { // get a object GetInterface(key string, defValue ...interface{}) (res interface{}) // get a string GetString(key string, defValue ...string) (res string) // get a bool GetBoolean(key string, defValue ...bool) (b bool) // get a int GetInt(key string, defValue ...int) (res int) // get a float GetFloat(key string, defValue ...float64) (res float64) // get list of objects GetList(key string) (res []interface{}) // get list of strings GetStringList(key string) []string // get list of bools GetBooleanList(key string) []bool // get list of ints GetIntList(key string) []int // get list of float64s GetFloatList(key string) []float64 // get time duration by (int)(uint), exp: 1s, 1day GetTimeDuration(key string, defValue ...time.Duration) time.Duration // get byte size by (int)(uint), exp: 1k, 1m GetByteSize(key string) *big.Int // get map value GetMap(key string) Options // get key's config GetConfig(key string) Config // ToObject unmarshal values to object ToObject(key string, model interface{}) error // get key's values if values can be Config, or panic GetValuesConfig(key string) Config // set key's value into config SetKeyValue(key string, value interface{}) (err error) // get all config Dump() (bs []byte, err error) // get all keys GetKeys() []string // deep copy configs Copy() Config }
Config manager data functions
func NewAdapterConfig ¶ added in v1.3.0
NewAdapterConfig return default config adapter name is file's path
func NewConfig ¶
NewConfig return Config by file's path, judge path's suffix, supported .json, .yml, .yaml
func NewConfigOptions ¶ added in v1.3.0
func NewConfigOptions(opts ...OptionFunc) (Config, error)
NewConfigOptions 从操作函数解析Config
type OptionFunc ¶ added in v1.5.0
type OptionFunc func(*AdapterConfig)
OptionFunc 处理函数
func OptionFile ¶ added in v1.3.0
func OptionFile(filename string) OptionFunc
OptionFile 解析配置文件Option函数
func OptionString ¶ added in v1.3.0
func OptionString(rt ReaderType, cStr string) OptionFunc
OptionString 字符串解析配置Option函数
func OptionStruct ¶ added in v1.5.0
func OptionStruct(rt ReaderType, st interface{}) OptionFunc
OptionStruct 结构体解析配置Option函数
type Options ¶
type Options map[string]interface{}
Options initial params
func (*Options) ToConfig ¶ added in v1.5.0
func (p *Options) ToConfig(rts ...ReaderType) Config
ToConfig Options to config, default YAML reader
type Reader ¶
type Reader interface { // read file into model Read(model interface{}) error // dump configs' cache Dump(model interface{}) ([]byte, error) // parse data to model ParseData(data []byte, model interface{}) error }
Reader reader repo
func NewJSONReader ¶
func NewJSONReader(opts ...ReaderOptionFunc) Reader
NewJSONReader return a json reader
func NewReader ¶ added in v1.3.0
func NewReader(rt ReaderType, filename string) (Reader, error)
NewReader return a reader by ReaderType
func NewSuffixReader ¶
func NewSuffixReader(opts ...ReaderOptionFunc) (reader Reader, err error)
NewSuffixReader return a suffix reader supportted: .json, .xml, .yaml, .yml
func NewXMLReader ¶
func NewXMLReader(opts ...ReaderOptionFunc) Reader
NewXMLReader return xml config reader
func NewYAMLReader ¶
func NewYAMLReader(opts ...ReaderOptionFunc) Reader
NewYAMLReader return a yaml reader
type ReaderOptionFunc ¶ added in v1.5.0
type ReaderOptionFunc func(*ReaderOptions)
ReaderOptionFunc declare reader option function
func ReaderOptionFilename ¶ added in v1.5.0
func ReaderOptionFilename(filename string) ReaderOptionFunc
ReaderOptionFilename set reader filename
type ReaderOptions ¶ added in v1.5.0
type ReaderOptions struct {
// contains filtered or unexported fields
}
ReaderOptions reader options
type ReaderType ¶
type ReaderType int
ReaderType define reader type
const ( // ReaderTypeSuffix judge by file suffix ReaderTypeSuffix ReaderType = iota // ReaderTypeJSON json reader type ReaderTypeJSON // ReaderTypeYAML yaml reader type ReaderTypeYAML // ReaderTypeXML xml reader type ReaderTypeXML )