config

package
v0.3.1 Latest Latest
Warning

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

Go to latest
Published: Sep 25, 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(username, password, address string) []source.Source

func Get

func Get(field *field.Field) reader.Value

Get a value from the config

func GetBool

func GetBool(field *field.Field) bool

GetString through field

func GetBoxName

func GetBoxName() string

GetBoxName path: box.name

func GetDuration

func GetDuration(field *field.Field) time.Duration

GetDuration through field

func GetFloat64

func GetFloat64(field *field.Field) float64

GetFloat64 through field

func GetInt

func GetInt(field *field.Field) int

GetInt through field

func GetString

func GetString(field *field.Field) string

GetString through field

func GetStringMap

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

GetStringMap through field

func GetStringSlice

func GetStringSlice(field *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.Field) uint

GetUint through field

func Load

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

Load config sources

func Mount

func Mount(fields ...*field.Field)

Mount fields

func SimpleSource

func SimpleSource(filePath string) []source.Source

func SprintFields

func SprintFields() string

SprintFields registered fields

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
	// Watch, Mount, Getter value through field
	SubConfigurator
}

Configurator is an interface abstraction for dynamic configuration

func NewConfig

func NewConfig(opts ...Option) Configurator

NewConfig returns new config

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(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.Field) (Watcher, error)
	// Mount fields to configurator
	Mount(fields ...*field.Field)
	// Get value through field
	Get(field *field.Field) reader.Value
	// GetString through field
	GetBool(field *field.Field) bool
	// GetInt through field
	GetInt(field *field.Field) int
	// GetUint through field
	GetUint(field *field.Field) uint
	// GetString through field
	GetString(field *field.Field) string
	// GetFloat64 through field
	GetFloat64(field *field.Field) float64
	// GetDuration through field
	GetDuration(field *field.Field) time.Duration
	// GetStringSlice through field
	GetStringSlice(field *field.Field) []string
	// GetStringMap through field
	GetStringMap(field *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.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