config

package
v1.0.0-beta Latest Latest
Warning

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

Go to latest
Published: Nov 13, 2020 License: Apache-2.0 Imports: 20 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 Byte added in v1.0.0

func Byte() []byte

Byte return config raw data

func Close

func Close() error

Close stop the config loader/watcher

func Fields

func Fields() *field.Fields

func Get

func Get(path ...string) reader.Value

Get a value from the config

func Load

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

Load config sources

func Scan added in v1.0.0

func Scan(val Config) error

Scan config to val

func Sync

func Sync() error

Sync force a source changeset sync

Types

type Config added in v1.0.0

type Config interface {
	Path() string
}

Config is set of config fields. "." is a level splitter. For example:

father.child

It means that config data's struct same as this.

{
  "father": {
    "child": {xxx}
  }
}

type Configurator

type Configurator interface {
	// Load config sources
	Load(source ...source.Source) error
	// Force a source change set sync
	Sync() error
	// Stop the config loader/watcher
	Close() error
	// Bytes get merged config data
	Bytes() []byte
	// Scan to val
	Scan(val Config) error
	// Watch field change
	Watch(path ...string) (Watcher, error)
	// Get value through field
	Get(path ...string) reader.Value
	// Scanned fields
	Fields() *field.Fields
}

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 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 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 Watcher

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

Watcher is the config watcher

func Watch

func Watch(path ...string) (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