config

package
v1.5.2 Latest Latest
Warning

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

Go to latest
Published: Oct 17, 2020 License: Apache-2.0 Imports: 18 Imported by: 5

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddBackend

func AddBackend(scheme string, backend Backend)

AddBackend add backend

func GetConfig

func GetConfig() interface{}

GetConfig set default config for a instance

func GetPrefixKeys added in v1.2.0

func GetPrefixKeys(key string, target interface{}) (ret []string)

GetPrefixKeys get the prefix keys by target

func Init

func Init(opts ...Option) error

Init init default config

func SetFieldListener

func SetFieldListener(field string, onchange OnChange)

AddFieldListener bind some trigger when config is changed if field is "", it add listen whole config

func Unmarshal

func Unmarshal(key string, kvs []*KV, target interface{}) (err error)

Unmarshal unmarshal interface to kv array

Types

type Backend

type Backend interface {
	LoadConfig(options Options) error
}

Backend defines a configuration backend, implement this interface to support additional backends, such as etcd, consul, file ...

type Config

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

Config the struct of config instance

func New

func New(defaultConfig interface{}) *Config

New new config use default config for config

func StandardConfig

func StandardConfig() *Config

StandardConfig return instance of default config

func (*Config) AddBackend

func (c *Config) AddBackend(scheme string, backend Backend)

AddBackend add backend

func (*Config) GetConfig

func (c *Config) GetConfig() interface{}

GetConfig set default config for a instance

func (*Config) Init

func (c *Config) Init(opts ...Option) error

Init init config by url

func (*Config) SetFieldListener

func (c *Config) SetFieldListener(field string, onChange OnChange)

SetFieldListener bind some trigger when config is changed

type KV

type KV struct {
	Key   string `json:"key,omitempty"`
	Value string `json:"value,omitempty"`
}

KV the key value of a interface

func Marshal

func Marshal(key string, target interface{}) (kvs []*KV, err error)

Marshal unmarshal interface to kv array

type OnChange

type OnChange func(pre, current interface{})

OnChange Trigger On config change function

type OnLoaded

type OnLoaded func(cfg interface{})

OnLoaded Trigger On config is loaded

type Option

type Option func(*Options)

Option is just Option functions

func ReloadDelay

func ReloadDelay(t time.Duration) Option

Timeout load timeout

func Timeout

func Timeout(t time.Duration) Option

Timeout load timeout

func URL

func URL(uri string) Option

URL is the registry addresses to use exp: etcd://127.0.0.1:6379,127.0.0.1:7379/xl/config/key exp: file://conf/service.yaml

func Watch

func Watch(w bool) Option

Watch if keep the etcd connections and watch notify

func WithDefault

func WithDefault(defaultConfig interface{}) Option

WithDefault set default config of the instance

type Options

type Options struct {
	URL     string
	Timeout time.Duration
	//ReloadDelay refresh the config after some time, it used for etcd, consul for the backend may not notify the config
	ReloadDelay time.Duration
	//Watch is watch is true, the etcd will keep connection for mq notify
	Watch bool
	//DefaultConfig default config
	DefaultConfig interface{}
	//OnLoaded ! do not set this Manually, this is internal usage
	OnLoaded OnLoaded
	// Other options for implementations of the interface
	// can be stored in a context
	Context context.Context
	// contains filtered or unexported fields
}

Options the Options of config

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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