gcfg

package
v1.4.7 Latest Latest
Warning

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

Go to latest
Published: Feb 1, 2019 License: MIT Imports: 12 Imported by: 0

Documentation

Overview

Package gcfg provides reading, caching and managing for configuration files.

配置管理, 配置文件格式支持:json, xml, toml, yaml/yml

Index

Constants

View Source
const (
	DEFAULT_CONFIG_FILE = "config.toml" // 默认的配置管理文件名称
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

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

配置管理对象

func New

func New(path string, file ...string) *Config

生成一个配置管理对象

func (*Config) AddPath

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

添加配置管理器的配置文件搜索路径

func (*Config) Get

func (c *Config) Get(pattern string, file ...string) interface{}

获取配置项,当不存在时返回nil

func (*Config) GetArray

func (c *Config) GetArray(pattern string, file ...string) []interface{}

获得一个数组[]interface{},方便操作,不需要自己做类型转换 注意,如果获取的值不存在,或者类型与json类型不匹配,那么将会返回nil

func (*Config) GetBool

func (c *Config) GetBool(pattern string, file ...string) bool

返回指定json中的bool

func (*Config) GetFilePath

func (c *Config) GetFilePath(file ...string) string

获取指定文件的绝对路径,默认获取默认的配置文件路径

func (*Config) GetFloat32

func (c *Config) GetFloat32(pattern string, file ...string) float32

返回指定json中的float32

func (*Config) GetFloat64

func (c *Config) GetFloat64(pattern string, file ...string) float64

返回指定json中的float64

func (*Config) GetFloats

func (c *Config) GetFloats(pattern string, file ...string) []float64

func (*Config) GetInt

func (c *Config) GetInt(pattern string, file ...string) int

返回指定json中的float64->int

func (*Config) GetInt16

func (c *Config) GetInt16(pattern string, file ...string) int16

func (*Config) GetInt32

func (c *Config) GetInt32(pattern string, file ...string) int32

func (*Config) GetInt64

func (c *Config) GetInt64(pattern string, file ...string) int64

func (*Config) GetInt8

func (c *Config) GetInt8(pattern string, file ...string) int8

func (*Config) GetInterfaces

func (c *Config) GetInterfaces(pattern string, file ...string) []interface{}

func (*Config) GetInts

func (c *Config) GetInts(pattern string, file ...string) []int

func (*Config) GetMap

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

获得一个键值对关联数组/哈希表,方便操作,不需要自己做类型转换 注意,如果获取的值不存在,或者类型与json类型不匹配,那么将会返回nil

func (*Config) GetString

func (c *Config) GetString(pattern string, file ...string) string

返回指定json中的string

func (*Config) GetStrings

func (c *Config) GetStrings(pattern string, file ...string) []string

func (*Config) GetToStruct

func (c *Config) GetToStruct(pattern string, objPointer interface{}, file ...string) error

func (*Config) GetUint

func (c *Config) GetUint(pattern string, file ...string) uint

返回指定json中的float64->uint

func (*Config) GetUint16

func (c *Config) GetUint16(pattern string, file ...string) uint16

func (*Config) GetUint32

func (c *Config) GetUint32(pattern string, file ...string) uint32

func (*Config) GetUint64

func (c *Config) GetUint64(pattern string, file ...string) uint64

func (*Config) GetUint8

func (c *Config) GetUint8(pattern string, file ...string) uint8

func (*Config) GetVar added in v1.1.994

func (c *Config) GetVar(pattern string, file ...string) gvar.VarRead

获得配置项,返回动态变量

func (*Config) Reload

func (c *Config) Reload()

清空当前配置文件缓存,强制重新从磁盘文件读取配置文件内容

func (*Config) SetFileName

func (c *Config) SetFileName(name string)

设置配置管理对象的默认文件名称

func (*Config) SetPath

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

设置配置管理器的配置文件存放目录绝对路径

func (*Config) SetViolenceCheck

func (c *Config) SetViolenceCheck(check bool)

设置是否执行层级冲突检查,当键名中存在层级符号时需要开启该特性,默认为关闭。 开启比较耗性能,也不建议允许键名中存在分隔符,最好在应用端避免这种情况。

Jump to

Keyboard shortcuts

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