config

package
v0.2.8 Latest Latest
Warning

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

Go to latest
Published: Jun 24, 2022 License: MIT Imports: 9 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

func ReloadEach added in v0.1.10

func ReloadEach(reloadable Reloadable, dur time.Duration, stopCh <-chan struct{})

ReloadEach call Reload for reloadable each dur, ignore error, util stopCh be closed

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 Duration added in v0.1.10

type Duration time.Duration

func (Duration) MarshalJSON added in v0.1.10

func (dur Duration) MarshalJSON() ([]byte, error)

func (*Duration) UnmarshalJSON added in v0.1.10

func (dur *Duration) UnmarshalJSON(data []byte) error

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 Regexp added in v0.1.10

type Regexp struct {
	*regexp.Regexp // note: zero value is nil, not ""
}

func (Regexp) MarshalJSON added in v0.1.10

func (reg Regexp) MarshalJSON() ([]byte, error)

func (*Regexp) UnmarshalJSON added in v0.1.10

func (reg *Regexp) UnmarshalJSON(data []byte) error

type Reloadable added in v0.1.10

type Reloadable interface {
	Reload() error
}

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