Documentation ¶
Index ¶
- Variables
- func GetInt(key string) (int, error)
- func GetIntWithDefault(key string, def int) int
- func GetJSON(key string, val interface{}) error
- func GetString(key string) (string, error)
- func GetStringWithDefault(key, def string) string
- func GetTOML(key string, val interface{}) error
- func GetWithUnmarshal(key string, val interface{}, unmarshalName string) error
- func GetYAML(key string, val interface{}) error
- func Register(c KVConfig)
- func RegisterCodec(c Codec)
- func RegisterProvider(p DataProvider)
- func RegisterUnmarshaler(name string, us Unmarshaler)
- func SetGlobalKV(kv KV)
- type Codec
- type Config
- type DataProvider
- type EventType
- type FileProvider
- type JSONCodec
- type JSONUnmarshaler
- type KV
- type KVConfig
- type Loader
- type Option
- type ProviderCallback
- type Response
- type TomlCodec
- type TomlUnmarshaler
- type Unmarshaler
- type Watcher
- type YamlCodec
- type YamlUnmarshaler
Constants ¶
This section is empty.
Variables ¶
Functions ¶
func GetIntWithDefault ¶
GetIntWithDefault 根据key获取Int类型的值,如果获取错误就使用 def 指定的默认值
func GetStringWithDefault ¶
GetStringWithDefault 根据 key 获取 string 类型的值,如果获取错误就使用 def 指定的默认值
func GetWithUnmarshal ¶
GetWithUnmarshal 根据key获取特定编码的数据结构
func RegisterUnmarshaler ¶
func RegisterUnmarshaler(name string, us Unmarshaler)
RegisterUnmarshaler 注册Unmarshaler
Types ¶
type Config ¶
type Config interface { Load() error Reload() Get(string, interface{}) interface{} Unmarshal(interface{}) error IsSet(string) bool GetInt(string, int) int GetInt32(string, int32) int32 GetInt64(string, int64) int64 GetUint(string, uint) uint GetUint32(string, uint32) uint32 GetUint64(string, uint64) uint64 GetFloat32(string, float32) float32 GetFloat64(string, float64) float64 GetString(string, string) string GetBool(string, bool) bool Bytes() []byte }
Config 配置通用接口
type DataProvider ¶
type DataProvider interface { //TODO:add ability to watch Name() string Read(string) ([]byte, error) Watch(ProviderCallback) }
DataProvider 通用内容源接口 通过实现Name、Read、Watch等方法,就能从任意的 内容源(file、TConf、ETCD、configmap)中读取配 置并通过编解码器解析为可处理的标准格式(JSON、TOML、YAML)等
type FileProvider ¶
type FileProvider struct {
// contains filtered or unexported fields
}
FileProvider 从文件系统拉取文件内容
type JSONUnmarshaler ¶
type JSONUnmarshaler struct{}
JSONUnmarshaler json解码
func (*JSONUnmarshaler) Unmarshal ¶
func (ju *JSONUnmarshaler) Unmarshal(data []byte, val interface{}) error
Unmarshal json 解码
type KV ¶
type KV interface { // Put 设置或更新配置项key对应的值 Put(ctx context.Context, key, val string, opts ...Option) error // Get 获取配置项key对应的值 Get(ctx context.Context, key string, opts ...Option) (Response, error) // Del 删除配置项key Del(ctx context.Context, key string, opts ...Option) error }
KV 配置中心键值对接口
type Loader ¶
type Loader interface { //TODO:complete the design of interface based on tconf. Passing a struct may not be a good choice Load(string) (Config, error) Reload(string) error }
Loader 解析配置的通用接口
type ProviderCallback ¶
ProviderCallback provider内容变更事件回调函数
type Response ¶
type Response interface { // Value 获取配置项对应的值 Value() string // MetaData 额外元数据信息 // 配置Option选项,可用于承载不同配置中心的额外功能实现,例如namespace,group,租约等概念 MetaData() map[string]string // Event 获取Watch事件类型 Event() EventType }
Response 配置中心响应
type TomlUnmarshaler ¶
type TomlUnmarshaler struct{}
TomlUnmarshaler toml解码
func (*TomlUnmarshaler) Unmarshal ¶
func (tu *TomlUnmarshaler) Unmarshal(data []byte, val interface{}) error
Unmarshal toml解码
type Unmarshaler ¶
Unmarshaler 配置内容解析抽象
type Watcher ¶
type Watcher interface { // Watch 监听配置项key的变更事件 Watch(ctx context.Context, key string, opts ...Option) (<-chan Response, error) }
Watcher 配置中心Watch事件接口
type YamlUnmarshaler ¶
type YamlUnmarshaler struct{}
YamlUnmarshaler yaml解码
func (*YamlUnmarshaler) Unmarshal ¶
func (yu *YamlUnmarshaler) Unmarshal(data []byte, val interface{}) error
Unmarshal yaml 解压
Click to show internal directories.
Click to hide internal directories.