Documentation ¶
Index ¶
- Variables
- func DeepCopy(value interface{}) interface{}
- func ParseJSONData(data []byte, model interface{}) error
- func ParseXMLConfig(data []byte, model interface{}) error
- func ParseYAMLData(data []byte, model interface{}) error
- func ParseYAMLFileToModel(name string, model interface{}) error
- func ReadFile(name string) ([]byte, error)
- func ReadJSONFileToModel(filepath string, model interface{}) 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, defValue ...*big.Int) *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{}) (err error)
- type Config
- type OptionFunc
- type Options
- type Reader
- type ReaderOptionFunc
- type ReaderOptions
- type ReaderType
Constants ¶
This section is empty.
Variables ¶
var ( ErrNotMap = errcode.New("interface is not a map") ErrInvalidKey = errcode.New("invalid key") ErrInvalidFilePath = errcode.New("invalid file path") ErrUnknownSuffixes = errcode.New("unknown file with suffix") ErrNotSupportedReaderType = errcode.New("not supported reader type") )
Errors
Functions ¶
func ParseJSONData ¶
ParseJSONData 解析Json配置
func ParseXMLConfig ¶
ParseXMLConfig 解析yaml的配置信息
func ParseYAMLData ¶
ParseYAMLData 解析yaml的配置信息
func ParseYAMLFileToModel ¶
ParseYAMLFileToModel 读取yaml文件的配置信息
func ReadJSONFileToModel ¶
ReadJSONFileToModel 读取Json文件数据到Models
Types ¶
type AdapterConfig ¶
type AdapterConfig struct { ConfigFile string ConfigString string ConfigStruct interface{} EnvPrefix string EnvAllowed bool // contains filtered or unexported fields }
AdapterConfig default config adapter
func (*AdapterConfig) Dump ¶
func (p *AdapterConfig) Dump() (bs []byte, err error)
Dump return p.configs' bytes
func (*AdapterConfig) GetBoolean ¶
func (p *AdapterConfig) GetBoolean(key string, defValue ...bool) (b bool)
GetBoolean return a bool object in p.configs by key
func (*AdapterConfig) GetBooleanList ¶
func (p *AdapterConfig) GetBooleanList(key string) []bool
GetBooleanList return a list of booleans in p.configs by key
func (*AdapterConfig) GetByteSize ¶
GetByteSize return time in p.configs by key
func (*AdapterConfig) GetConfig ¶
func (p *AdapterConfig) GetConfig(key string) Config
GetConfig return object config in p.configs by key
func (*AdapterConfig) GetFloat ¶
func (p *AdapterConfig) GetFloat(key string, defValue ...float64) (res float64)
GetFloat return a float object in p.configs by key
func (*AdapterConfig) GetFloatList ¶
func (p *AdapterConfig) GetFloatList(key string) []float64
GetFloatList return a list of floats in p.configs by key
func (*AdapterConfig) GetInt ¶
func (p *AdapterConfig) GetInt(key string, defValue ...int) (res int)
GetInt return a int object in p.configs by key
func (*AdapterConfig) GetIntList ¶
func (p *AdapterConfig) GetIntList(key string) []int
GetIntList return a list of ints in p.configs by key
func (*AdapterConfig) GetInterface ¶
func (p *AdapterConfig) GetInterface(key string, defValue ...interface{}) (res interface{})
GetInterface return a interface object in p.configs by key
func (*AdapterConfig) GetKeyValue ¶
func (p *AdapterConfig) GetKeyValue(key string) (vm interface{}, err error)
GetKeyValue get value with key
func (*AdapterConfig) GetList ¶
func (p *AdapterConfig) GetList(key string) (res []interface{})
GetList return a list of interface{} in p.configs by key
func (*AdapterConfig) GetMap ¶
func (p *AdapterConfig) GetMap(key string) Options
GetMap get map value
func (*AdapterConfig) GetString ¶
func (p *AdapterConfig) GetString(key string, defValue ...string) (res string)
GetString return a string object in p.configs by key
func (*AdapterConfig) GetStringList ¶
func (p *AdapterConfig) GetStringList(key string) []string
GetStringList return a list of strings in p.configs by key
func (*AdapterConfig) GetTimeDuration ¶
GetTimeDuration return time in p.configs by key
func (*AdapterConfig) GetValuesConfig ¶
func (p *AdapterConfig) GetValuesConfig(key string) Config
GetValuesConfig get key's values if values can be Config, or panic
func (*AdapterConfig) SetKeyValue ¶
func (p *AdapterConfig) SetKeyValue(key string, value interface{}) (err error)
SetKeyValue set key value into p.configs
func (*AdapterConfig) ToObject ¶
func (p *AdapterConfig) ToObject(key string, model interface{}) (err error)
ToObject unmarshal values to object
type Config ¶
type Config interface { // GetInterface get a object GetInterface(key string, defValue ...interface{}) (res interface{}) // GetString get a string GetString(key string, defValue ...string) (res string) // GetBoolean get a bool GetBoolean(key string, defValue ...bool) (b bool) // GetInt get a int GetInt(key string, defValue ...int) (res int) // GetFloat get a float GetFloat(key string, defValue ...float64) (res float64) // GetList get list of objects GetList(key string) (res []interface{}) // GetStringList get list of strings GetStringList(key string) []string // GetBooleanList get list of bools GetBooleanList(key string) []bool // GetIntList get list of ints GetIntList(key string) []int // GetFloatList get list of float64s GetFloatList(key string) []float64 // GetTimeDuration get time duration by (int)(uint), exp: 1s, 1day GetTimeDuration(key string, defValue ...time.Duration) time.Duration // GetByteSize get byte size by (int)(uint), exp: 1k, 1m GetByteSize(key string, defValue ...*big.Int) *big.Int // GetMap get map value GetMap(key string) Options // GetConfig get key's config GetConfig(key string) Config // ToObject unmarshal values to object ToObject(key string, model interface{}) error // GetValuesConfig get key's values if values can be Config, or panic GetValuesConfig(key string) Config // SetKeyValue set key's value into config SetKeyValue(key string, value interface{}) (err error) // Dump get all config Dump() (bs []byte, err error) // GetKeys get all keys GetKeys() []string // Copy deep copy configs Copy() Config }
Config manager data functions
func NewAdapterConfig ¶
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 ¶
func NewConfigOptions(opts ...OptionFunc) (Config, error)
NewConfigOptions 从操作函数解析Config
type OptionFunc ¶
type OptionFunc func(*AdapterConfig)
OptionFunc 处理函数
func OptionENVPrefix ¶
func OptionENVPrefix(prefix string) OptionFunc
OptionENVPrefix 设置环境变量已自定义字符串开始
func OptionString ¶
func OptionString(rt ReaderType, cStr string) OptionFunc
OptionString 字符串解析配置Option函数
func OptionStruct ¶
func OptionStruct(rt ReaderType, st interface{}) OptionFunc
OptionStruct 结构体解析配置Option函数
type Options ¶
type Options map[string]interface{}
Options initial params
func (*Options) ToConfig ¶
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) // ParseData 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 ¶
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 supported: .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 ¶
type ReaderOptionFunc func(*ReaderOptions)
ReaderOptionFunc declare reader option function
func ReaderOptionFilename ¶
func ReaderOptionFilename(filename string) ReaderOptionFunc
ReaderOptionFilename set reader filename
type ReaderOptions ¶
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 )