Documentation ¶
Overview ¶
Package config provides common config interface.
Index ¶
- Variables
- func GetInt(key string) (int, error)
- func GetIntWithDefault(key string, def int) int
- func GetJSON(key string, val interface{}) error
- func GetJSONWithProvider(key string, val interface{}, provider string) error
- func GetString(key string) (string, error)
- func GetStringWithDefault(key, def string) string
- func GetTOML(key string, val interface{}) error
- func GetTOMLWithProvider(key string, val interface{}, provider string) error
- func GetWithUnmarshal(key string, val interface{}, unmarshalName string) error
- func GetWithUnmarshalProvider(key string, val interface{}, unmarshalName string, provider string) error
- func GetYAML(key string, val interface{}) error
- func GetYAMLWithProvider(key string, val interface{}, provider string) error
- func Register(c KVConfig)
- func RegisterCodec(c Codec)
- func RegisterProvider(p DataProvider)
- func RegisterUnmarshaler(name string, us Unmarshaler)
- func Reload(path string, opts ...LoadOption) error
- func SetGlobalKV(kv KV)
- type Codec
- type Config
- type DataProvider
- type EventType
- type FileProvider
- type JSONCodec
- type JSONUnmarshaler
- type KV
- type KVConfig
- type LoadOption
- type Option
- type ProviderCallback
- type Response
- type TomlCodec
- type TomlUnmarshaler
- type TrpcConfig
- func (c *TrpcConfig) Bytes() []byte
- func (c *TrpcConfig) Get(key string, defaultValue interface{}) interface{}
- func (c *TrpcConfig) GetBool(key string, defaultValue bool) bool
- func (c *TrpcConfig) GetFloat32(key string, defaultValue float32) float32
- func (c *TrpcConfig) GetFloat64(key string, defaultValue float64) float64
- func (c *TrpcConfig) GetInt(key string, defaultValue int) int
- func (c *TrpcConfig) GetInt32(key string, defaultValue int32) int32
- func (c *TrpcConfig) GetInt64(key string, defaultValue int64) int64
- func (c *TrpcConfig) GetString(key string, defaultValue string) string
- func (c *TrpcConfig) GetUint(key string, defaultValue uint) uint
- func (c *TrpcConfig) GetUint32(key string, defaultValue uint32) uint32
- func (c *TrpcConfig) GetUint64(key string, defaultValue uint64) uint64
- func (c *TrpcConfig) IsSet(key string) bool
- func (c *TrpcConfig) Load() error
- func (c *TrpcConfig) Reload()
- func (c *TrpcConfig) Unmarshal(out interface{}) error
- type TrpcConfigLoader
- type Unmarshaler
- type Watcher
- type YamlCodec
- type YamlUnmarshaler
Constants ¶
This section is empty.
Variables ¶
var ( // ErrConfigNotExist is config not exist error ErrConfigNotExist = errors.New("trpc/config: config not exist") // ErrProviderNotExist is provider not exist error ErrProviderNotExist = errors.New("trpc/config: provider not exist") // ErrCodecNotExist is codec not exist error ErrCodecNotExist = errors.New("trpc/config: codec not exist") )
var DefaultConfigLoader = newTrpcConfigLoad()
DefaultConfigLoader is the default config loader.
var ErrConfigNotSupport = errors.New("trpc/config: not support")
ErrConfigNotSupport is not supported config error
Functions ¶
func GetIntWithDefault ¶
GetIntWithDefault returns int value get by key. If anything wrong, returns default value specified by input param def.
func GetJSONWithProvider ¶
GetJSONWithProvider gets json data by key. The value will unmarshal into val parameter the provider name is defined by provider parameter.
func GetStringWithDefault ¶
GetStringWithDefault returns string value get by key. If anything wrong, returns default value specified by input param def.
func GetTOMLWithProvider ¶
GetTOMLWithProvider gets toml data by key. The value will unmarshal into val parameter the provider name is defined by provider parameter.
func GetWithUnmarshal ¶
GetWithUnmarshal gets the specific encoding data by key. the encoding type is defined by unmarshalName parameter.
func GetWithUnmarshalProvider ¶
func GetWithUnmarshalProvider(key string, val interface{}, unmarshalName string, provider string) error
GetWithUnmarshalProvider gets the specific encoding data by key the encoding type is defined by unmarshalName parameter the provider name is defined by provider parameter.
func GetYAMLWithProvider ¶
GetYAMLWithProvider gets yaml data by key. The value will unmarshal into val parameter the provider name is defined by provider parameter.
func RegisterProvider ¶
func RegisterProvider(p DataProvider)
RegisterProvider registers a data provider by its name.
func RegisterUnmarshaler ¶
func RegisterUnmarshaler(name string, us Unmarshaler)
RegisterUnmarshaler registers an unmarshaler by name.
Types ¶
type Codec ¶
type Codec interface { // Name returns codec's name. Name() string // Unmarshal deserializes the config data bytes into // the second input parameter. Unmarshal([]byte, interface{}) error }
Codec defines codec interface.
type Config ¶
type Config interface { // Load loads config. Load() error // Reload reloads config. Reload() // Get returns config by key. Get(string, interface{}) interface{} // Unmarshal deserializes the config into input param. Unmarshal(interface{}) error // IsSet returns if the config specified by key exists. IsSet(string) bool // GetInt returns int value by key, the second parameter // is default value when key is absent or type conversion fails. GetInt(string, int) int // GetInt32 returns int32 value by key, the second parameter // is default value when key is absent or type conversion fails. GetInt32(string, int32) int32 // GetInt64 returns int64 value by key, the second parameter // is default value when key is absent or type conversion fails. GetInt64(string, int64) int64 // GetUint returns uint value by key, the second parameter // is default value when key is absent or type conversion fails. GetUint(string, uint) uint // GetUint32 returns uint32 value by key, the second parameter // is default value when key is absent or type conversion fails. GetUint32(string, uint32) uint32 // GetUint64 returns uint64 value by key, the second parameter // is default value when key is absent or type conversion fails. GetUint64(string, uint64) uint64 // GetFloat32 returns float32 value by key, the second parameter // is default value when key is absent or type conversion fails. GetFloat32(string, float32) float32 // GetFloat64 returns float64 value by key, the second parameter // is default value when key is absent or type conversion fails. GetFloat64(string, float64) float64 // GetString returns string value by key, the second parameter // is default value when key is absent or type conversion fails. GetString(string, string) string // GetBool returns bool value by key, the second parameter // is default value when key is absent or type conversion fails. GetBool(string, bool) bool // Bytes returns config data as bytes. Bytes() []byte }
Config defines the common config interface. We can implement different config center by this interface.
type DataProvider ¶
type DataProvider interface { // Name returns the data provider's name. Name() string // Read reads the specific path file, returns // it content as bytes. Read(string) ([]byte, error) // Watch watches config changing. The change will // be handled by callback function. Watch(ProviderCallback) }
DataProvider defines common data provider interface. we can implement this interface to define different data provider( such as file, TConf, ETCD, configmap) and parse config data to standard format( such as json, toml, yaml, etc.) by codec.
func GetProvider ¶
func GetProvider(name string) DataProvider
GetProvider returns the provider by name.
type FileProvider ¶
type FileProvider struct {
// contains filtered or unexported fields
}
FileProvider is a config provider which gets config from file system.
func (*FileProvider) Read ¶
func (fp *FileProvider) Read(path string) ([]byte, error)
Read reads the specific path file, returns it content as bytes.
func (*FileProvider) Watch ¶
func (fp *FileProvider) Watch(cb ProviderCallback)
Watch watches config changing. The change will be handled by callback function.
type JSONUnmarshaler ¶
type JSONUnmarshaler struct{}
JSONUnmarshaler is json unmarshaler.
func (*JSONUnmarshaler) Unmarshal ¶
func (ju *JSONUnmarshaler) Unmarshal(data []byte, val interface{}) error
Unmarshal deserializes the data bytes into parameter val in json protocol.
type KV ¶
type KV interface { // Put puts or updates config value by key. Put(ctx context.Context, key, val string, opts ...Option) error // Get returns config value by key. Get(ctx context.Context, key string, opts ...Option) (Response, error) // Del deletes config value by key. Del(ctx context.Context, key string, opts ...Option) error }
KV defines a kv storage for config center.
type LoadOption ¶
type LoadOption func(*TrpcConfig)
LoadOption defines the option function for loading configuration.
func WithCodec ¶
func WithCodec(name string) LoadOption
WithCodec returns an option which sets the codec's name.
func WithProvider ¶
func WithProvider(name string) LoadOption
WithProvider returns an option which sets the provider's name.
type ProviderCallback ¶
ProviderCallback is callback function for provider to handle config change.
type Response ¶
type Response interface { // Value returns config value as string. Value() string // MetaData returns extra metadata. With option, // we can implement some extra features for different config center, // such as namespace, group, lease, etc. MetaData() map[string]string // Event returns the type of watch event. Event() EventType }
Response defines config center's response interface.
type TomlUnmarshaler ¶
type TomlUnmarshaler struct{}
TomlUnmarshaler is toml unmarshaler.
func (*TomlUnmarshaler) Unmarshal ¶
func (tu *TomlUnmarshaler) Unmarshal(data []byte, val interface{}) error
Unmarshal deserializes the data bytes into parameter val in toml protocol.
type TrpcConfig ¶
type TrpcConfig struct {
// contains filtered or unexported fields
}
TrpcConfig is used to parse yaml config file for trpc.
func (*TrpcConfig) Bytes ¶
func (c *TrpcConfig) Bytes() []byte
Bytes returns original config data as bytes.
func (*TrpcConfig) Get ¶
func (c *TrpcConfig) Get(key string, defaultValue interface{}) interface{}
Get returns config value by key. If key is absent will return the default value.
func (*TrpcConfig) GetBool ¶
func (c *TrpcConfig) GetBool(key string, defaultValue bool) bool
GetBool returns bool value by key, the second parameter is default value when key is absent or type conversion fails.
func (*TrpcConfig) GetFloat32 ¶
func (c *TrpcConfig) GetFloat32(key string, defaultValue float32) float32
GetFloat32 returns float32 value by key, the second parameter is default value when key is absent or type conversion fails.
func (*TrpcConfig) GetFloat64 ¶
func (c *TrpcConfig) GetFloat64(key string, defaultValue float64) float64
GetFloat64 returns float64 value by key, the second parameter is default value when key is absent or type conversion fails.
func (*TrpcConfig) GetInt ¶
func (c *TrpcConfig) GetInt(key string, defaultValue int) int
GetInt returns int value by key, the second parameter is default value when key is absent or type conversion fails.
func (*TrpcConfig) GetInt32 ¶
func (c *TrpcConfig) GetInt32(key string, defaultValue int32) int32
GetInt32 returns int32 value by key, the second parameter is default value when key is absent or type conversion fails.
func (*TrpcConfig) GetInt64 ¶
func (c *TrpcConfig) GetInt64(key string, defaultValue int64) int64
GetInt64 returns int64 value by key, the second parameter is default value when key is absent or type conversion fails.
func (*TrpcConfig) GetString ¶
func (c *TrpcConfig) GetString(key string, defaultValue string) string
GetString returns string value by key, the second parameter is default value when key is absent or type conversion fails.
func (*TrpcConfig) GetUint ¶
func (c *TrpcConfig) GetUint(key string, defaultValue uint) uint
GetUint returns uint value by key, the second parameter is default value when key is absent or type conversion fails.
func (*TrpcConfig) GetUint32 ¶
func (c *TrpcConfig) GetUint32(key string, defaultValue uint32) uint32
GetUint32 returns uint32 value by key, the second parameter is default value when key is absent or type conversion fails.
func (*TrpcConfig) GetUint64 ¶
func (c *TrpcConfig) GetUint64(key string, defaultValue uint64) uint64
GetUint64 returns uint64 value by key, the second parameter is default value when key is absent or type conversion fails.
func (*TrpcConfig) IsSet ¶
func (c *TrpcConfig) IsSet(key string) bool
IsSet returns if the config specified by key exists.
func (*TrpcConfig) Unmarshal ¶
func (c *TrpcConfig) Unmarshal(out interface{}) error
Unmarshal deserializes the config into input param.
type TrpcConfigLoader ¶
type TrpcConfigLoader struct {
// contains filtered or unexported fields
}
TrpcConfigLoader is a config loader for trpc.
func (*TrpcConfigLoader) Load ¶
func (loader *TrpcConfigLoader) Load(path string, opts ...LoadOption) (Config, error)
Load returns the config specified by input parameter.
func (*TrpcConfigLoader) Reload ¶
func (loader *TrpcConfigLoader) Reload(path string, opts ...LoadOption) error
Reload reloads config data.
type Unmarshaler ¶
type Unmarshaler interface { // Unmarshal deserializes the data bytes into value parameter. Unmarshal(data []byte, value interface{}) error }
Unmarshaler defines a unmarshal interface, this will be used to parse config data.
func GetUnmarshaler ¶
func GetUnmarshaler(name string) Unmarshaler
GetUnmarshaler returns an unmarshaler by name.
type Watcher ¶
type Watcher interface { // Watch watches the config key change event. Watch(ctx context.Context, key string, opts ...Option) (<-chan Response, error) }
Watcher defines the interface of config center watch event.
type YamlUnmarshaler ¶
type YamlUnmarshaler struct{}
YamlUnmarshaler is yaml unmarshaler.
func (*YamlUnmarshaler) Unmarshal ¶
func (yu *YamlUnmarshaler) Unmarshal(data []byte, val interface{}) error
Unmarshal deserializes the data bytes into parameter val in yaml protocol.
Directories ¶
Path | Synopsis |
---|---|
Package mockconfig is a generated GoMock package.
|
Package mockconfig is a generated GoMock package. |