Documentation
¶
Index ¶
- type Config
- func (c *Config) AddParser(ext string, parser IConfigParser)
- func (c *Config) AddPath(path string)
- func (c *Config) CheckPath() error
- func (c *Config) Get(key string, dftSplit ...string) interface{}
- func (c *Config) GetBool(key string, dft bool, dftSplit ...string) bool
- func (c *Config) GetFloat(key string, dft float64, dftSplit ...string) float64
- func (c *Config) GetInt(key string, dft int, dftSplit ...string) int
- func (c *Config) GetSliceBool(key string, dftSplit ...string) []bool
- func (c *Config) GetSliceFloat(key string, dftSplit ...string) []float64
- func (c *Config) GetSliceInt(key string, dftSplit ...string) []int
- func (c *Config) GetSliceString(key string, dftSplit ...string) []string
- func (c *Config) GetString(key string, dft string, dftSplit ...string) string
- func (c *Config) Init()
- func (c *Config) Set(key string, val interface{}, dftSplit ...string)
- type IConfig
- type IConfigParser
- type JsonParser
- type YamlParser
- func (y *YamlParser) Parse(path string) (parseData map[string]interface{}, err error)
- func (y *YamlParser) YamlDecode(r io.Reader, out interface{}, strict ...bool) error
- func (y *YamlParser) YamlEncode(w io.Writer, in interface{}) error
- func (y *YamlParser) YamlMarshal(in interface{}) ([]byte, error)
- func (y *YamlParser) YamlUnmarshal(in []byte, out interface{}, strict ...bool) error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Config ¶
type Config struct {
// contains filtered or unexported fields
}
Config the config component
func (*Config) AddParser ¶
func (c *Config) AddParser(ext string, parser IConfigParser)
AddParser add parser for file with ext extension
func (*Config) Get ¶
Get get value by dot separated key, the first part of key is file name without extension. if key is empty, all loaded config will be returned.
func (*Config) GetBool ¶
GetBool get bool value from config, key is dot separated config key, dft is default value if key not exists.
func (*Config) GetFloat ¶
GetFloat get float value from config, key is dot separated config key, dft is default value if key not exists.
func (*Config) GetInt ¶
GetInt get int value from config, key is dot separated config key, dft is default value if key not exists.
func (*Config) GetSliceBool ¶
GetSliceBool get []bool value from config, key is dot separated config key, nil is default value if key not exists.
func (*Config) GetSliceFloat ¶
GetSliceFloat get []float value from config, key is dot separated config key, nil is default value if key not exists.
func (*Config) GetSliceInt ¶
GetSliceInt get []int value from config, key is dot separated config key, nil is default value if key not exists.
func (*Config) GetSliceString ¶
GetSliceString get []string value from config, key is dot separated config key, nil is default value if key not exists.
type IConfig ¶
type IConfig interface { AddParser(ext string, parser IConfigParser) AddPath(path string) GetBool(key string, dft bool, dftSplit ...string) bool GetInt(key string, dft int, dftSplit ...string) int GetFloat(key string, dft float64, dftSplit ...string) float64 GetString(key string, dft string, dftSplit ...string) string GetSliceBool(key string, dftSplit ...string) []bool GetSliceInt(key string, dftSplit ...string) []int GetSliceFloat(key string, dftSplit ...string) []float64 GetSliceString(key string, dftSplit ...string) []string Get(key string, dftSplit ...string) interface{} Set(key string, val interface{}, dftSplit ...string) CheckPath() error }
type IConfigParser ¶
type JsonParser ¶
type JsonParser struct {
// contains filtered or unexported fields
}
JsonParser parser for json config
type YamlParser ¶
type YamlParser struct {
// contains filtered or unexported fields
}
YamlParser parser for yaml config
func (*YamlParser) Parse ¶
func (y *YamlParser) Parse(path string) (parseData map[string]interface{}, err error)
Parse parse yaml config, environment value like ${env||default} will expand
func (*YamlParser) YamlDecode ¶
func (y *YamlParser) YamlDecode(r io.Reader, out interface{}, strict ...bool) error
YamlDecode wrapper for yaml.Decoder, strict is for Decoder.SetStrict(). if type of out is map[string]interface{}, *map[string]interface{}, the inner map[interface{}]interface{} will fix to map[string]interface{} recursively. if type of out is *interface{}, the underlying type of out will change to *map[string]interface{}.
func (*YamlParser) YamlEncode ¶
func (y *YamlParser) YamlEncode(w io.Writer, in interface{}) error
YamlEncode wrapper for yaml.Encoder.
func (*YamlParser) YamlMarshal ¶
func (y *YamlParser) YamlMarshal(in interface{}) ([]byte, error)
YamlMarshal wrapper for yaml.Marshal.
func (*YamlParser) YamlUnmarshal ¶
func (y *YamlParser) YamlUnmarshal(in []byte, out interface{}, strict ...bool) error
YamlUnmarshal wrapper for yaml.Unmarshal or yaml.UnmarshalStrict, if type of out is map[string]interface{}, *map[string]interface{}, the inner map[interface{}]interface{} will fix to map[string]interface{} recursively. if type of out is *interface{}, the underlying type of out will change to *map[string]interface{}.