config

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Sep 22, 2020 License: Apache-2.0 Imports: 17 Imported by: 0

Documentation

Overview

Package config is an interface for dynamic configuration.

Index

Constants

This section is empty.

Variables

View Source
var (
	// Default Config Manager
	Default = NewConfig()
)

Functions

func ClassicSource

func ClassicSource(filePath, username, password, address string) []source.Source

func Close

func Close() error

Stop the config loader/watcher

func EtcdSource

func EtcdSource(prefix, username, password, address string) []source.Source

func Get

func Get(field *Field) reader.Value

Get a value from the config

func GetBool

func GetBool(field *Field) bool

GetString through field

func GetBoxName

func GetBoxName() string

GetBoxName path: box.name

func GetDuration

func GetDuration(field *Field) time.Duration

GetDuration through field

func GetFloat64

func GetFloat64(field *Field) float64

GetFloat64 through field

func GetInt

func GetInt(field *Field) int

GetInt through field

func GetString

func GetString(field *Field) string

GetString through field

func GetStringMap

func GetStringMap(field *Field) map[string]string

GetStringMap through field

func GetStringSlice

func GetStringSlice(field *Field) []string

GetStringSlice through field

func GetTraceBizId

func GetTraceBizId() string

GetTraceBizId path: box.trace.bizid

func GetTraceReqId

func GetTraceReqId() string

GetTraceReqId path: box.trace.reqid

func GetTraceSpanId

func GetTraceSpanId() string

GetTraceSpanId path: box.trace.spanid

func GetTraceUid

func GetTraceUid() string

GetTraceUid path: box.trace.uid

func GetUint

func GetUint(field *Field) uint

GetUint through field

func Load

func Load(source ...source.Source) error

Load config sources

func Mount

func Mount(fields ...*Field)

Mount fields

func SimpleSource

func SimpleSource(filePath string) []source.Source

func SprintFields

func SprintFields() string

SprintFields registered fields

func SprintTemplate

func SprintTemplate(encoder string) string

SprintTemplate through encoder

func Sync

func Sync() error

Force a source changeset sync

Types

type Configurator

type Configurator interface {
	// Load config sources
	Load(source ...source.Source) error
	// Force a source changeset sync
	Sync() error
	// Stop the config loader/watcher
	Close() error
	// Bytes get merged config data
	Bytes() []byte
	// SprintFields registered fields
	SprintFields() string
	// SprintTemplate through encoder
	SprintTemplate(encoder string) string
	// Watch, Mount, Getter value through field
	SubConfigurator
}

Configurator is an interface abstraction for dynamic configuration

func NewClassic

func NewClassic(filePath, username, password, address string) Configurator

NewClassic create a configurator with `file`, `env` and `etcd` source support. the priority is: `etcd` > `env` > `file`. `env` will use filename as prefix automatically. `etcd` key format: `/{fileName}/config`

func NewConfig

func NewConfig(opts ...Option) Configurator

NewConfig returns new config

func NewEtcd

func NewEtcd(prefix, username, password, address string) Configurator

NewEtcd create a configurator with `etcd` source support. `etcd` key format: `/{prefix}/config`

func NewSimple

func NewSimple(filePath string) Configurator

NewSimple create a configurator with `file` and `env` source support. the priority is: `env` > `file`. `env` will use filename as prefix automatically.

type Field

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

func NewField

func NewField(name, path, desc string, def interface{}) *Field

func (Field) String

func (f Field) String() string

type Fields

type Fields []*Field

func (*Fields) Append

func (fs *Fields) Append(fields ...*Field) *Fields

func (Fields) Len

func (fs Fields) Len() int

func (Fields) Less

func (fs Fields) Less(i, j int) bool

func (*Fields) Sort

func (fs *Fields) Sort() *Fields

func (Fields) Swap

func (fs Fields) Swap(i, j int)

type Option

type Option func(o *Options)

func WithClassicSource

func WithClassicSource(filePath, username, password, address string) Option

WithClassicSource create a option with `file`, `env` and `etcd` source support. the priority is: `etcd` > `env` > `file`. `env` will use filename as prefix automatically. `etcd` key format: `/{fileName}/config`

func WithEtcdSource

func WithEtcdSource(prefix, username, password, address string) Option

WithEtcdSource create a option with `etcd` source support. `etcd` key format: `/{prefix}/config`

func WithLoader

func WithLoader(l loader.Loader) Option

WithLoader sets the loader for manager config

func WithReader

func WithReader(r reader.Reader) Option

WithReader sets the config reader

func WithSimpleSource

func WithSimpleSource(filePath string) Option

WithSimpleSource create a option with `file` and `env` source support. the priority is: `env` > `file`. `env` will use filename as prefix automatically.

func WithSource

func WithSource(s ...source.Source) Option

WithSource appends a source to list of sources

type Options

type Options struct {
	Loader loader.Loader
	Reader reader.Reader
	Source []source.Source

	// for alternative data
	Context context.Context
}

type SubConfigurator

type SubConfigurator interface {
	// Watch field change
	Watch(field *Field) (Watcher, error)
	// Mount fields to configurator
	Mount(fields ...*Field)
	// Get value through field
	Get(field *Field) reader.Value
	// GetString through field
	GetBool(field *Field) bool
	// GetInt through field
	GetInt(field *Field) int
	// GetUint through field
	GetUint(field *Field) uint
	// GetString through field
	GetString(field *Field) string
	// GetFloat64 through field
	GetFloat64(field *Field) float64
	// GetDuration through field
	GetDuration(field *Field) time.Duration
	// GetStringSlice through field
	GetStringSlice(field *Field) []string
	// GetStringMap through field
	GetStringMap(field *Field) map[string]string
	// GetBoxName path: box.name
	GetBoxName() string
	// GetTraceUid path: box.trace.uid
	GetTraceUid() string
	// GetTraceReqId path: box.trace.reqid
	GetTraceReqId() string
	// GetTraceBizId path: box.trace.bizid
	GetTraceBizId() string
	// GetTraceSpanId path: box.trace.spanid
	GetTraceSpanId() string
}

type Watcher

type Watcher interface {
	Next() (reader.Value, error)
	Stop() error
}

Watcher is the config watcher

func Watch

func Watch(field *Field) (Watcher, error)

Watch a value for changes

Directories

Path Synopsis
Package encoder handles source encoding formats
Package encoder handles source encoding formats
xml
Package loader manages loading from multiple sources
Package loader manages loading from multiple sources
Package reader parses change sets and provides config values
Package reader parses change sets and provides config values
Package source is the interface for sources
Package source is the interface for sources
env
file
Package file is a file source.
Package file is a file source.

Jump to

Keyboard shortcuts

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