config

package
v1.0.35 Latest Latest
Warning

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

Go to latest
Published: Apr 16, 2024 License: Apache-2.0 Imports: 21 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 AppendServiceTag added in v1.0.0

func AppendServiceTag(tags ...string)

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 ServiceName added in v1.0.0

func ServiceName() string

func ServiceTag added in v1.0.0

func ServiceTag() []string

func ServiceVersion added in v1.0.0

func ServiceVersion() string

func SetServiceTag added in v1.0.0

func SetServiceTag(tags ...string)

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
	// Sync force a source change set sync
	Sync() error
	// Close 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
	// Fields return 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 Source added in v1.0.0

type Source struct {
	Type string `config:"type"`
	// contains filtered or unexported fields
}

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