config

package
v0.1.5 Latest Latest
Warning

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

Go to latest
Published: Mar 18, 2021 License: MIT Imports: 7 Imported by: 0

README

Config

ConfigAccessor

Help to reload config from getter, and allow register handler for reload error and config changed.

see ca_accessor_test for usage.

MultiAccessor

A map for ConfigAccessor.

see ca_multi_test for usage.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Accessor

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

zero value is not ready to use, call NewAccessor to create

func NewAccessor

func NewAccessor(getter Getter, explainer Explainer, validator Validator) *Accessor

for accessor itself, only getter is required for most of use case, explainer is expected

func (*Accessor) Config

func (a *Accessor) Config() Config

func (*Accessor) OnChange

func (a *Accessor) OnChange(onChange func(oldConfig, newConfig Config))

func (*Accessor) OnError

func (a *Accessor) OnError(onError func(err error))

func (*Accessor) Reload

func (a *Accessor) Reload() error

type Config

type Config struct {
	Raw       string      `json:"raw,omitempty"`
	Value     interface{} `json:"value"` // value is Ptr to real config, but must treat it as read only
	UpdatedAt time.Time   `json:"updated_at"`
}

type Explainer

type Explainer func(raw string) (interface{}, error)

func NewCommonJSONExplainer

func NewCommonJSONExplainer(v interface{}) Explainer

type Getter

type Getter func() (string, error)

type MultiAccessor

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

zero value is ready to use

func (*MultiAccessor) Accessor

func (ma *MultiAccessor) Accessor(key string) *Accessor

func (*MultiAccessor) AddAccessor

func (ma *MultiAccessor) AddAccessor(key string, a *Accessor)

func (*MultiAccessor) Config

func (ma *MultiAccessor) Config(key string) Config

func (*MultiAccessor) Configs

func (ma *MultiAccessor) Configs() map[string]Config

func (*MultiAccessor) GetAccessor

func (ma *MultiAccessor) GetAccessor(key string) (*Accessor, bool)

func (*MultiAccessor) GetConfig

func (ma *MultiAccessor) GetConfig(key string) (Config, bool)

func (*MultiAccessor) Reload

func (ma *MultiAccessor) Reload() error

func (*MultiAccessor) ReloadEach

func (ma *MultiAccessor) ReloadEach(dur time.Duration, stopCh <-chan struct{})

type Validator

type Validator func(raw string, v interface{}) error

Jump to

Keyboard shortcuts

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