dcfg

package
v0.1.9 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 9, 2021 License: MIT Imports: 20 Imported by: 0

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

Examples

Constants

View Source
const (
	DefaultName       = "config"      //
	DefaultConfigFile = "config.toml" //默认的配置文件名字

)

Variables

This section is empty.

Functions

func ClearContent

func ClearContent()

ClearContent 清空所有的配置文件内容

func GetContent

func GetContent(file ...string) string

GetContent 获取配置文件内容

func RemoveContent

func RemoveContent(file ...string)

RemoveContent 设置指定的配置文件内容

func SetContent

func SetContent(content string, file ...string)

SetContent 写入配置文件内容到指定的文件映射对象,注意不会改变源文件 如果不传入文件名,则写入到默认配置文件中

Types

type Config

type Config struct {
	// contains filtered or unexported fields
}

Config 配置信息结构体

func Instance

func Instance(name ...string) *Config

Instance 通过名字获取全局配置实例. 默认是使用"toml"后缀的配置文件

func New

func New(file ...string) *Config

New 创建一个配置文件对象,可以传入指定的文件名

func (*Config) AddPath

func (that *Config) AddPath(path string) error

AddPath 添加路径到搜索路径列表

func (*Config) Available

func (that *Config) Available(file ...string) bool

Available 检查指定的配置文件中的配置是否可用

func (*Config) Clear

func (that *Config) Clear()

Clear 删除所有已解析的配置文件内容缓存, 这将强制从文件重新加载配置内容。

func (*Config) Contains

func (that *Config) Contains(pattern string) bool

Contains 判断配置项是否存在

func (*Config) Dump

func (that *Config) Dump()

Dump 打印当前Json对象,更具手动可读性。

func (*Config) Get

func (that *Config) Get(pattern string, def ...interface{}) interface{}

Get 获取配置文件的选项

func (*Config) GetArray

func (that *Config) GetArray(pattern string, def ...interface{}) []interface{}

GetArray 获取数组格式的配置项

func (*Config) GetBool

func (that *Config) GetBool(pattern string, def ...interface{}) bool

func (*Config) GetBytes

func (that *Config) GetBytes(pattern string, def ...interface{}) []byte

GetBytes 获取配置项的字节数组类型

func (*Config) GetDuration

func (that *Config) GetDuration(pattern string, def ...interface{}) time.Duration

GetDuration retrieves the value by specified `pattern` and converts it to time.Duration.

func (*Config) GetFileName

func (that *Config) GetFileName() string

GetFileName 获取配置文件名

func (*Config) GetFilePath

func (that *Config) GetFilePath(file ...string) (path string, err error)

func (*Config) GetFloat32

func (that *Config) GetFloat32(pattern string, def ...interface{}) float32

GetFloat32 retrieves the value by specified `pattern` and converts it to float32.

func (*Config) GetFloat64

func (that *Config) GetFloat64(pattern string, def ...interface{}) float64

GetFloat64 retrieves the value by specified `pattern` and converts it to float64.

func (*Config) GetFloats

func (that *Config) GetFloats(pattern string, def ...interface{}) []float64

GetFloats retrieves the value by specified `pattern` and converts it to []float64.

func (*Config) GetGTime

func (that *Config) GetGTime(pattern string, format ...string) *gtime.Time

Getdtime retrieves the value by specified `pattern` and converts it to *dtime.Time.

func (*Config) GetInt

func (that *Config) GetInt(pattern string, def ...interface{}) int

GetInt retrieves the value by specified `pattern` and converts it to int.

func (*Config) GetInt16

func (that *Config) GetInt16(pattern string, def ...interface{}) int16

GetInt16 retrieves the value by specified `pattern` and converts it to int16.

func (*Config) GetInt32

func (that *Config) GetInt32(pattern string, def ...interface{}) int32

GetInt32 retrieves the value by specified `pattern` and converts it to int32.

func (*Config) GetInt64

func (that *Config) GetInt64(pattern string, def ...interface{}) int64

GetInt64 retrieves the value by specified `pattern` and converts it to int64.

func (*Config) GetInt8

func (that *Config) GetInt8(pattern string, def ...interface{}) int8

GetInt8 retrieves the value by specified `pattern` and converts it to int8.

func (*Config) GetInterfaces

func (that *Config) GetInterfaces(pattern string, def ...interface{}) []interface{}

GetInterfaces 获取数组格式的配置项

func (*Config) GetInts

func (that *Config) GetInts(pattern string, def ...interface{}) []int

GetInts retrieves the value by specified `pattern` and converts it to []int.

func (*Config) GetJson

func (that *Config) GetJson(pattern string, def ...interface{}) *gjson.Json

GetJson gets the value by specified `pattern`, and converts it to a un-concurrent-safe Json object.

func (*Config) GetJsonMap

func (that *Config) GetJsonMap(pattern string, def ...interface{}) map[string]*gjson.Json

GetJsonMap gets the value by specified `pattern`, and converts it to a map of un-concurrent-safe Json object.

func (*Config) GetJsons

func (that *Config) GetJsons(pattern string, def ...interface{}) []*gjson.Json

GetJsons gets the value by specified `pattern`, and converts it to a slice of un-concurrent-safe Json object.

func (*Config) GetMap

func (that *Config) GetMap(pattern string, def ...interface{}) map[string]interface{}

GetMap 获取map格式的配置项

func (*Config) GetMapStrStr

func (that *Config) GetMapStrStr(pattern string, def ...interface{}) map[string]string

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) GetString

func (that *Config) GetString(pattern string, def ...interface{}) string

GetString 获取字符串类型的配置项

func (*Config) GetStrings

func (that *Config) GetStrings(pattern string, def ...interface{}) []string

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

func (that *Config) GetTime(pattern string, format ...string) time.Time

GetTime retrieves the value by specified `pattern` and converts it to time.Time.

func (*Config) GetUint

func (that *Config) GetUint(pattern string, def ...interface{}) uint

GetUint retrieves the value by specified `pattern` and converts it to uint.

func (*Config) GetUint16

func (that *Config) GetUint16(pattern string, def ...interface{}) uint16

GetUint16 retrieves the value by specified `pattern` and converts it to uint16.

func (*Config) GetUint32

func (that *Config) GetUint32(pattern string, def ...interface{}) uint32

GetUint32 retrieves the value by specified `pattern` and converts it to uint32.

func (*Config) GetUint64

func (that *Config) GetUint64(pattern string, def ...interface{}) uint64

GetUint64 retrieves the value by specified `pattern` and converts it to uint64.

func (*Config) GetUint8

func (that *Config) GetUint8(pattern string, def ...interface{}) uint8

GetUint8 retrieves the value by specified `pattern` and converts it to uint8.

func (*Config) GetVar

func (that *Config) GetVar(pattern string, def ...interface{}) *dvar.Var

GetVar 返回`pattern`对应的Var对象

func (*Config) Set

func (that *Config) Set(pattern string, value interface{}) error

Set 修改内存中的配置内容

func (*Config) SetFileName

func (that *Config) SetFileName(name string) *Config

SetFileName 设置配置文件名

func (*Config) SetPath

func (that *Config) SetPath(path string) error

SetPath 设置配置文件的搜索路径,可以是绝对路径也可以是相对路径

func (*Config) SetViolenceCheck

func (that *Config) SetViolenceCheck(check bool)

SetViolenceCheck 设置是否进行分级冲突检查。 当键名中有级别符号时,需要启用此功能。 默认是关闭的。 注意,打开这个特性的代价是非常昂贵的,不建议在键名中允许分隔符。最好在应用程序端避免这种情况。

func (*Config) ToArray

func (that *Config) ToArray() []interface{}

ToArray converts current Json object to []interface{}. It returns nil if fails.

func (*Config) ToMap

func (that *Config) ToMap() map[string]interface{}

ToMap 将当前Json对象转换为 map[string]interface{}. 如果失败返回nil。

func (*Config) ToMapToMap

func (that *Config) ToMapToMap(pointer interface{}, mapping ...map[string]string) error

ToMapToMap 将当前Json对象转换为指定的映射变量。 指针的形参应该是*map类型。

func (*Config) ToMapToMaps

func (that *Config) ToMapToMaps(pointer interface{}, mapping ...map[string]string) error

ToMapToMaps 将当前Json对象转换为指定的映射变量切片。 指针的参数应该是[]map/*map类型。

func (*Config) ToMapToMapsDeep

func (that *Config) ToMapToMapsDeep(pointer interface{}, mapping ...map[string]string) error

ToMapToMapsDeep 将当前Json对象递归转换为指定的映射变量切片。 指针的参数应该是[]map/*map类型。

func (*Config) ToStruct

func (that *Config) ToStruct(pointer interface{}, mapping ...map[string]string) error

ToStruct 将当前Json对象转换为指定对象。 指针应该是*struct类型的指针。

func (*Config) ToStructDeep

func (that *Config) ToStructDeep(pointer interface{}, mapping ...map[string]string) error

ToStructDeep 将当前Json对象递归转换为指定对象。 指针应该是*struct类型的指针。

func (*Config) ToStructs

func (that *Config) ToStructs(pointer interface{}, mapping ...map[string]string) error

ToStructs 将当前Json对象转换为指定的对象切片。 指针类型应该是[]struct/*struct。

func (*Config) ToStructsDeep

func (that *Config) ToStructsDeep(pointer interface{}, mapping ...map[string]string) error

ToStructsDeep 将当前Json对象递归转换为指定的对象切片。 指针类型应该是[]struct/*struct。

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL