retune

package module
v0.0.0-...-6d592e1 Latest Latest
Warning

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

Go to latest
Published: Nov 6, 2022 License: Apache-2.0 Imports: 10 Imported by: 1

README

Retune

Retune is a stable port of go-micro.dev/v4/config, providing a pluggable library for working with static and dynamic configuration in 12-Factor applications written in Go.

Features

  • Dynamic Loading - Load configuration from multiple source as and when needed. Go Config manages watching config sources in the background and automatically merges and updates an in memory view.

  • Pluggable Sources - Choose from any number of sources to load and merge config. The backend source is abstracted away into a standard format consumed internally and decoded via encoders. Sources can be env vars, flags, file, etcd, k8s configmap, etc.

  • Mergeable Config - If you specify multiple sources of config, regardless of format, they will be merged and presented in a single view. This massively simplifies priority order loading and changes based on environment.

  • Observe Changes - Optionally watch the config for changes to specific values. Hot reload your app using Go Config's watcher. You don't have to handle ad-hoc hup reloading or whatever else, just keep reading the config and watch for changes if you need to be notified.

  • Sane Defaults - In case config loads badly or is completely wiped away for some unknown reason, you can specify fallback values when accessing any config values directly. This ensures you'll always be reading some sane default in the event of a problem.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// Default Config Manager
	DefaultConfig, _ = NewConfig()
)

Functions

func Bytes

func Bytes() []byte

Return config as raw json

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 LoadFile

func LoadFile(path string) error

LoadFile is short hand for creating a file source and loading it

func Map

func Map() map[string]interface{}

Return config as a map

func Scan

func Scan(v interface{}) error

Scan values to a go type

func Sync

func Sync() error

Force a source changeset sync

Types

type Config

type Config interface {
	// provide the reader.Values interface
	reader.Values
	// Init the config
	Init(opts ...Option) error
	// Options in the config
	Options() Options
	// Stop the config loader/watcher
	Close() error
	// Load config sources
	Load(source ...source.Source) error
	// Force a source changeset sync
	Sync() error
	// Watch a value for changes
	Watch(path ...string) (Watcher, error)
}

Config is an interface abstraction for dynamic configuration

func NewConfig

func NewConfig(opts ...Option) (Config, error)

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 WithWatcherDisabled

func WithWatcherDisabled() Option

type Options

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

	// for alternative data
	Context context.Context

	WithWatcherDisabled bool
}

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
hcl
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.
memory
Package memory is a memory source
Package memory is a memory source

Jump to

Keyboard shortcuts

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