Documentation ¶
Index ¶
- Variables
- func NewConfigSource(opt *BootstrapOption) (source.ConfigSource, error)
- type BootstrapOption
- func (opt *BootstrapOption) Validate() error
- func (opt *BootstrapOption) WithAddr(addr string) *BootstrapOption
- func (opt *BootstrapOption) WithAddrs(addrs []string) *BootstrapOption
- func (opt *BootstrapOption) WithGroup(group string) *BootstrapOption
- func (opt *BootstrapOption) WithIpPort(ip, port interface{}) *BootstrapOption
- func (opt *BootstrapOption) WithKey(key string) *BootstrapOption
- func (opt *BootstrapOption) WithLogger(lg log.Logger) *BootstrapOption
- func (opt *BootstrapOption) WithMinimalInterval(v time.Duration) *BootstrapOption
- func (opt *BootstrapOption) WithNamespace(ns string) *BootstrapOption
- func (opt *BootstrapOption) WithType(typ source.ConfigSourceType) *BootstrapOption
- type ConfigProxy
- type ConfigUpdateHandler
- type Manager
Constants ¶
This section is empty.
Variables ¶
var NOOPHandler = ConfigUpdateHandler{ Name: "noop", Handle: func(prev, cur interface{}) error { return nil }, }
NOOPHandler does nothing on config update
var NewBootstrapOptionFromEnvFlag = func() *BootstrapOption { opt := NewBootstrapOption() opt.parseEnvFlags() return opt }
NewBootstrapOptionFromEnvFlag initializes a bootstrap config option from environments & flags. Flag value has higher priority when both given in environments & flags. NOTE:
- Flags are parsed once this function is called.
- Customize this function if needed
Functions ¶
func NewConfigSource ¶
func NewConfigSource(opt *BootstrapOption) (source.ConfigSource, error)
Types ¶
type BootstrapOption ¶
type BootstrapOption struct { Type source.ConfigSourceType Format string Addrs []string Namespace string Group string Key string MinimalInterval time.Duration Logger log.Logger }
BootstrapOption is used to specify config source (and other additional) options.
func NewBootstrapOption ¶
func NewBootstrapOption() *BootstrapOption
NewBootstrapOption initializes a bootstrap config option
func (*BootstrapOption) Validate ¶
func (opt *BootstrapOption) Validate() error
Validate checks option values
func (*BootstrapOption) WithAddr ¶
func (opt *BootstrapOption) WithAddr(addr string) *BootstrapOption
WithAddr adds an address to the option
func (*BootstrapOption) WithAddrs ¶
func (opt *BootstrapOption) WithAddrs(addrs []string) *BootstrapOption
WithAddrs replaces option's addrs with given value
func (*BootstrapOption) WithGroup ¶
func (opt *BootstrapOption) WithGroup(group string) *BootstrapOption
WithGroup specifies config group
func (*BootstrapOption) WithIpPort ¶
func (opt *BootstrapOption) WithIpPort(ip, port interface{}) *BootstrapOption
WithIpPort adds an ip:port address to the option
func (*BootstrapOption) WithKey ¶
func (opt *BootstrapOption) WithKey(key string) *BootstrapOption
WithKey specifies config key
func (*BootstrapOption) WithLogger ¶
func (opt *BootstrapOption) WithLogger(lg log.Logger) *BootstrapOption
WithLogger specifies a custom logger to the option
func (*BootstrapOption) WithMinimalInterval ¶
func (opt *BootstrapOption) WithMinimalInterval(v time.Duration) *BootstrapOption
WithMinimalInterval specifies a minimal duration that config can be updated, defaults to 5s. This prevents your application being destroyed by event storm.
func (*BootstrapOption) WithNamespace ¶
func (opt *BootstrapOption) WithNamespace(ns string) *BootstrapOption
WithNamespace specifies config namespace
func (*BootstrapOption) WithType ¶
func (opt *BootstrapOption) WithType(typ source.ConfigSourceType) *BootstrapOption
WithType specifies config source type
type ConfigProxy ¶
type ConfigProxy interface { // Get always returns current config value holding by ConfigProxy Get() interface{} // Populate takes a closure function as input, fills new config data into its config value Populate(func(interface{}) error) error // New creates a ConfigProxy with an empty config instance New() ConfigProxy }
ConfigProxy is a proxy for user's business config, defining the way user's config is accessed & modified by konfig.Manager, as well as how to generate a brand-new config proxy.
When configuration was updated, a kconfig manager will: 1) Create a new temporary proxy using ConfigProxy.New 2) Wrap new config data (in bytes) in a closure function, then calls ConfigProxy.Populate 3) Call update handlers one by one 4) Call manager.ConfigProxy.Populate to update existing config
type ConfigUpdateHandler ¶
ConfigUpdateHandler is called when config change, it enables user to compare the new config with previous one, and decide what kind of action should be taken, e.g. reconnect database, refresh cache or send a notification.
type Manager ¶
type Manager struct {
// contains filtered or unexported fields
}
func New ¶
func New(proxy ConfigProxy, hdl ...ConfigUpdateHandler) (*Manager, error)
New creates a new Manager instance, which will automatically read BootstrapOption from environment & flags. Once created, Manager will read config data and update config with the help of types.ConfigProxy. hdl is a series of custom update handlers, will be called sequentially after Manager is created and when config is changed.
func NewWithOption ¶
func NewWithOption(proxy ConfigProxy, opt *BootstrapOption, hdl ...ConfigUpdateHandler) (*Manager, error)
NewWithOption creates a new Manager instance with given BootstrapOption.
func (*Manager) Register ¶
func (m *Manager) Register(hdl ...ConfigUpdateHandler) *Manager
Register registers extra event handlers after creation