Documentation ¶
Overview ¶
Example (MapSliceChange) ¶
package main import ( "fmt" "github.com/osgochina/donkeygo/internal/intlog" "github.com/osgochina/donkeygo/os/dcfg" ) func main() { intlog.SetEnabled(false) defer intlog.SetEnabled(true) // For testing/example only. content := `{"map":{"key":"value"}, "slice":[59,90]}` dcfg.SetContent(content) defer dcfg.RemoveContent() m := dcfg.Instance().GetMap("map") fmt.Println(m) // Change the key-value pair. m["key"] = "john" // It changes the underlying key-value pair. fmt.Println(dcfg.Instance().GetMap("map")) s := dcfg.Instance().GetArray("slice") fmt.Println(s) // Change the value of specified index. s[0] = 100 // It changes the underlying slice. fmt.Println(dcfg.Instance().GetArray("slice")) }
Output: map[key:value] map[key:john] [59 90] [100 90]
Index ¶
- Constants
- func ClearContent()
- func GetContent(file ...string) string
- func RemoveContent(file ...string)
- func SetContent(content string, file ...string)
- type Config
- func (that *Config) AddPath(path string) error
- func (that *Config) Available(file ...string) bool
- func (that *Config) Clear()
- func (that *Config) Contains(pattern string) bool
- func (that *Config) Dump()
- func (that *Config) Get(pattern string, def ...interface{}) interface{}
- func (that *Config) GetArray(pattern string, def ...interface{}) []interface{}
- func (that *Config) GetBool(pattern string, def ...interface{}) bool
- func (that *Config) GetBytes(pattern string, def ...interface{}) []byte
- func (that *Config) GetDuration(pattern string, def ...interface{}) time.Duration
- func (that *Config) GetFileName() string
- func (that *Config) GetFilePath(file ...string) (path string, err error)
- func (that *Config) GetFloat32(pattern string, def ...interface{}) float32
- func (that *Config) GetFloat64(pattern string, def ...interface{}) float64
- func (that *Config) GetFloats(pattern string, def ...interface{}) []float64
- func (that *Config) GetGTime(pattern string, format ...string) *gtime.Time
- func (that *Config) GetInt(pattern string, def ...interface{}) int
- func (that *Config) GetInt16(pattern string, def ...interface{}) int16
- func (that *Config) GetInt32(pattern string, def ...interface{}) int32
- func (that *Config) GetInt64(pattern string, def ...interface{}) int64
- func (that *Config) GetInt8(pattern string, def ...interface{}) int8
- func (that *Config) GetInterfaces(pattern string, def ...interface{}) []interface{}
- func (that *Config) GetInts(pattern string, def ...interface{}) []int
- func (that *Config) GetJson(pattern string, def ...interface{}) *gjson.Json
- func (that *Config) GetJsonMap(pattern string, def ...interface{}) map[string]*gjson.Json
- func (that *Config) GetJsons(pattern string, def ...interface{}) []*gjson.Json
- func (that *Config) GetMap(pattern string, def ...interface{}) map[string]interface{}
- func (that *Config) GetMapStrStr(pattern string, def ...interface{}) map[string]string
- func (that *Config) GetMapToMap(pattern string, pointer interface{}, mapping ...map[string]string) error
- func (that *Config) GetMapToMaps(pattern string, pointer interface{}, mapping ...map[string]string) error
- func (that *Config) GetMapToMapsDeep(pattern string, pointer interface{}, mapping ...map[string]string) error
- func (that *Config) GetString(pattern string, def ...interface{}) string
- func (that *Config) GetStrings(pattern string, def ...interface{}) []string
- func (that *Config) GetStruct(pattern string, pointer interface{}, mapping ...map[string]string) error
- func (that *Config) GetStructDeep(pattern string, pointer interface{}, mapping ...map[string]string) error
- func (that *Config) GetStructs(pattern string, pointer interface{}, mapping ...map[string]string) error
- func (that *Config) GetStructsDeep(pattern string, pointer interface{}, mapping ...map[string]string) error
- func (that *Config) GetTime(pattern string, format ...string) time.Time
- func (that *Config) GetUint(pattern string, def ...interface{}) uint
- func (that *Config) GetUint16(pattern string, def ...interface{}) uint16
- func (that *Config) GetUint32(pattern string, def ...interface{}) uint32
- func (that *Config) GetUint64(pattern string, def ...interface{}) uint64
- func (that *Config) GetUint8(pattern string, def ...interface{}) uint8
- func (that *Config) GetVar(pattern string, def ...interface{}) *dvar.Var
- func (that *Config) Set(pattern string, value interface{}) error
- func (that *Config) SetFileName(name string) *Config
- func (that *Config) SetPath(path string) error
- func (that *Config) SetViolenceCheck(check bool)
- func (that *Config) ToArray() []interface{}
- func (that *Config) ToMap() map[string]interface{}
- func (that *Config) ToMapToMap(pointer interface{}, mapping ...map[string]string) error
- func (that *Config) ToMapToMaps(pointer interface{}, mapping ...map[string]string) error
- func (that *Config) ToMapToMapsDeep(pointer interface{}, mapping ...map[string]string) error
- func (that *Config) ToStruct(pointer interface{}, mapping ...map[string]string) error
- func (that *Config) ToStructDeep(pointer interface{}, mapping ...map[string]string) error
- func (that *Config) ToStructs(pointer interface{}, mapping ...map[string]string) error
- func (that *Config) ToStructsDeep(pointer interface{}, mapping ...map[string]string) error
Examples ¶
Constants ¶
const ( DefaultName = "config" // DefaultConfigFile = "config.toml" //默认的配置文件名字 )
Variables ¶
This section is empty.
Functions ¶
func SetContent ¶
SetContent 写入配置文件内容到指定的文件映射对象,注意不会改变源文件 如果不传入文件名,则写入到默认配置文件中
Types ¶
type Config ¶
type Config struct {
// contains filtered or unexported fields
}
Config 配置信息结构体
func (*Config) GetDuration ¶
GetDuration retrieves the value by specified `pattern` and converts it to time.Duration.
func (*Config) GetFilePath ¶
func (*Config) GetFloat32 ¶
GetFloat32 retrieves the value by specified `pattern` and converts it to float32.
func (*Config) GetFloat64 ¶
GetFloat64 retrieves the value by specified `pattern` and converts it to float64.
func (*Config) GetFloats ¶
GetFloats retrieves the value by specified `pattern` and converts it to []float64.
func (*Config) GetGTime ¶
Getdtime retrieves the value by specified `pattern` and converts it to *dtime.Time.
func (*Config) GetInt16 ¶
GetInt16 retrieves the value by specified `pattern` and converts it to int16.
func (*Config) GetInt32 ¶
GetInt32 retrieves the value by specified `pattern` and converts it to int32.
func (*Config) GetInt64 ¶
GetInt64 retrieves the value by specified `pattern` and converts it to int64.
func (*Config) GetInt8 ¶
GetInt8 retrieves the value by specified `pattern` and converts it to int8.
func (*Config) GetInterfaces ¶
GetInterfaces 获取数组格式的配置项
func (*Config) GetInts ¶
GetInts retrieves the value by specified `pattern` and converts it to []int.
func (*Config) GetJson ¶
GetJson gets the value by specified `pattern`, and converts it to a un-concurrent-safe Json object.
func (*Config) GetJsonMap ¶
GetJsonMap gets the value by specified `pattern`, and converts it to a map of un-concurrent-safe Json object.
func (*Config) GetJsons ¶
GetJsons gets the value by specified `pattern`, and converts it to a slice of un-concurrent-safe Json object.
func (*Config) GetMapStrStr ¶
GetMapStrStr 获取 map[string]string格式的配置项
func (*Config) GetMapToMap ¶
func (that *Config) GetMapToMap(pattern string, pointer interface{}, mapping ...map[string]string) error
GetMapToMap 根据指定的“模式”检索值并将其转换为指定的映射变量。 See gconv.MapToMap.
func (*Config) GetMapToMaps ¶
func (that *Config) GetMapToMaps(pattern string, pointer interface{}, mapping ...map[string]string) error
GetMapToMaps 根据指定的“模式”检索值,并将其转换为指定的映射片变量。 See gconv.MapToMaps.
func (*Config) GetMapToMapsDeep ¶
func (that *Config) GetMapToMapsDeep(pattern string, pointer interface{}, mapping ...map[string]string) error
GetMapToMapsDeep 根据指定的“模式”检索值,并将其递归转换为指定的映射片变量。 See gconv.MapToMapsDeep.
func (*Config) GetStrings ¶
GetStrings 获取字符串数组配置项
func (*Config) GetStruct ¶
func (that *Config) GetStruct(pattern string, pointer interface{}, mapping ...map[string]string) error
GetStruct retrieves the value by specified `pattern` and converts it to specified object `pointer`. The `pointer` should be the pointer to an object.
func (*Config) GetStructDeep ¶
func (that *Config) GetStructDeep(pattern string, pointer interface{}, mapping ...map[string]string) error
GetStructDeep does GetStruct recursively. Deprecated, use GetStruct instead.
func (*Config) GetStructs ¶
func (that *Config) GetStructs(pattern string, pointer interface{}, mapping ...map[string]string) error
GetStructs 将任何片转换为给定的结构片。
func (*Config) GetStructsDeep ¶
func (that *Config) GetStructsDeep(pattern string, pointer interface{}, mapping ...map[string]string) error
GetStructsDeep 递归地将任何片转换为给定的结构片。 Deprecated, use GetStructs instead.
func (*Config) GetTime ¶
GetTime retrieves the value by specified `pattern` and converts it to time.Time.
func (*Config) GetUint ¶
GetUint retrieves the value by specified `pattern` and converts it to uint.
func (*Config) GetUint16 ¶
GetUint16 retrieves the value by specified `pattern` and converts it to uint16.
func (*Config) GetUint32 ¶
GetUint32 retrieves the value by specified `pattern` and converts it to uint32.
func (*Config) GetUint64 ¶
GetUint64 retrieves the value by specified `pattern` and converts it to uint64.
func (*Config) GetUint8 ¶
GetUint8 retrieves the value by specified `pattern` and converts it to uint8.
func (*Config) SetFileName ¶
SetFileName 设置配置文件名
func (*Config) SetViolenceCheck ¶
SetViolenceCheck 设置是否进行分级冲突检查。 当键名中有级别符号时,需要启用此功能。 默认是关闭的。 注意,打开这个特性的代价是非常昂贵的,不建议在键名中允许分隔符。最好在应用程序端避免这种情况。
func (*Config) ToArray ¶
func (that *Config) ToArray() []interface{}
ToArray converts current Json object to []interface{}. It returns nil if fails.
func (*Config) ToMapToMap ¶
ToMapToMap 将当前Json对象转换为指定的映射变量。 指针的形参应该是*map类型。
func (*Config) ToMapToMaps ¶
ToMapToMaps 将当前Json对象转换为指定的映射变量切片。 指针的参数应该是[]map/*map类型。
func (*Config) ToMapToMapsDeep ¶
ToMapToMapsDeep 将当前Json对象递归转换为指定的映射变量切片。 指针的参数应该是[]map/*map类型。
func (*Config) ToStructDeep ¶
ToStructDeep 将当前Json对象递归转换为指定对象。 指针应该是*struct类型的指针。