config

package
v0.0.0-...-499b7bf Latest Latest
Warning

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

Go to latest
Published: Oct 20, 2020 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DefaultConfig = NewConfig()
View Source
var (
	Unmarshals = map[string]Unmarshal{
		"json": json.Unmarshal,
		"xml":  xml.Unmarshal,
		"yaml": yaml.Unmarshal,
		"yml":  yaml.Unmarshal,
		"toml": toml.Unmarshal,
	}
)

Functions

func Load

func Load(sources source.Source) error

从数据源获取配置信息

func LoadFile

func LoadFile(path string) error

从文件中加载配置信息

func OnChange

func OnChange(fn ChangeFunc)

添加一个配置文件更改监听

func Set

func Set(path string, data interface{}) error

设置配置信息

func UnWatch

func UnWatch()

取消配置文件监听

func Watch

func Watch()

开启配置文件监听

Types

type ChangeFunc

type ChangeFunc func(v Value)

type Config

type Config interface {
	LoadSource(source source.Source) error
	Load(content []byte, format string) error
	Get(path string) Value
	Set(Path string, data interface{}) error
	OnChange(change ChangeFunc)
	UnWatch()
	Watch()
	Write() error
}

func NewConfig

func NewConfig() Config

创建一个新的config管理器

type JSONValue

type JSONValue struct {
	*simple.Json
}

func NewJSONValue

func NewJSONValue(data []byte) *JSONValue

func (*JSONValue) Bool

func (j *JSONValue) Bool(def bool) bool

func (*JSONValue) Bytes

func (j *JSONValue) Bytes() []byte

func (*JSONValue) Duration

func (j *JSONValue) Duration(def time.Duration) time.Duration

func (*JSONValue) Exists

func (j *JSONValue) Exists() bool

func (*JSONValue) Float64

func (j *JSONValue) Float64(def float64) float64

func (*JSONValue) Int

func (j *JSONValue) Int(def int) int

func (*JSONValue) Scan

func (j *JSONValue) Scan(v interface{}) error

func (*JSONValue) String

func (j *JSONValue) String(def string) string

func (*JSONValue) StringMap

func (j *JSONValue) StringMap(def map[string]string) map[string]string

func (*JSONValue) StringSlice

func (j *JSONValue) StringSlice(def []string) []string

type JSONValues

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

func NewJSONValues

func NewJSONValues(data []byte) *JSONValues

func (*JSONValues) Bytes

func (j *JSONValues) Bytes() []byte

func (*JSONValues) Delete

func (j *JSONValues) Delete(path string)

func (*JSONValues) Get

func (j *JSONValues) Get(path string) Value

func (*JSONValues) Map

func (j *JSONValues) Map() map[string]interface{}

func (*JSONValues) Scan

func (j *JSONValues) Scan(v interface{}) error

func (*JSONValues) Set

func (j *JSONValues) Set(path string, val interface{})

func (*JSONValues) String

func (j *JSONValues) String() string

type Unmarshal

type Unmarshal func(data []byte, v interface{}) error

type Value

type Value interface {
	Exists() bool
	Bool(def bool) bool
	Int(def int) int
	String(def string) string
	Float64(def float64) float64
	Duration(def time.Duration) time.Duration
	StringSlice(def []string) []string
	StringMap(def map[string]string) map[string]string
	Scan(val interface{}) error
	Bytes() []byte
}

Value represents a value of any type

func Get

func Get(path string) Value

获取配置信息

Jump to

Keyboard shortcuts

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