go-platform: github.com/micro/go-platform/config Index | Files | Directories

package config

import "github.com/micro/go-platform/config"

Package config is an interface for dynamic configuration.

Index

Package Files

config.go context.go options.go os.go reader.go source.go values.go watcher.go

Variables

var (
    DefaultPollInterval = time.Second * 30
    DefaultSourceName   = "MICRO:CONFIG"
)

func NewContext Uses

func NewContext(ctx context.Context, c Config) context.Context

type ChangeSet Uses

type ChangeSet struct {
    // The time at which the last change occured
    Timestamp time.Time
    // The raw data set for the change
    Data []byte
    // Hash of the source data
    Checksum string
    // The source of this change; file, consul, etcd
    Source string
}

ChangeSet represents a set an actual source

type Config Uses

type Config interface {
    // Config values
    Values
    // Config options
    Options() Options
    // Watch for changes
    Watch(path ...string) (Watcher, error)
    // Render config unusable
    Close() error
    // String name of config
    String() string
}

Config is the top level config which aggregates a number of sources and provides a single merged interface.

func FromContext Uses

func FromContext(ctx context.Context) (Config, bool)

func NewConfig Uses

func NewConfig(opts ...Option) Config

type Option Uses

type Option func(o *Options)

func PollInterval Uses

func PollInterval(i time.Duration) Option

PollInterval is the time interval at which the sources are polled to retrieve config.

func WithClient Uses

func WithClient(c client.Client) Option

func WithReader Uses

func WithReader(r Reader) Option

WithReader is the reader used by config to parse ChangeSets, merge them and provide values. We're not as elegant here in terms of encoding.

func WithSource Uses

func WithSource(s Source) Option

WithSource appends a source to our list of sources. This forms a hierarchy whereby all the configs are merged down with the last specified as favoured.

type Options Uses

type Options struct {
    PollInterval time.Duration
    Reader       Reader
    Sources      []Source
    Client       client.Client
}

type Reader Uses

type Reader interface {
    // Parse ChangeSets
    Parse(...*ChangeSet) (*ChangeSet, error)
    // As values
    Values(*ChangeSet) (Values, error)
    // Name of parser; json
    String() string
}

Reader takes a ChangeSet from a source and returns a single merged ChangeSet e.g reads ChangeSet as JSON and can merge down

func NewReader Uses

func NewReader() Reader

New json reader

type Source Uses

type Source interface {
    // Loads ChangeSet from the source
    Read() (*ChangeSet, error)
    // Watch for source changes
    // Returns the entire changeset
    Watch() (SourceWatcher, error)
    // Name of source
    String() string
}

Source is the source from which config is loaded. This may be a file, a url, consul, etc.

func NewSource Uses

func NewSource(opts ...SourceOption) Source

type SourceOption Uses

type SourceOption func(o *SourceOptions)

func SourceClient Uses

func SourceClient(c client.Client) SourceOption

func SourceHosts Uses

func SourceHosts(hosts ...string) SourceOption

func SourceName Uses

func SourceName(n string) SourceOption

SourceName is an option to provide name of a file, a url, key within etcd, consul, zookeeper, etc.

type SourceOptions Uses

type SourceOptions struct {
    // Name, Url, etc
    Name string

    // Client
    Client client.Client
    Hosts  []string

    // Extra Options
    Context context.Context
}

type SourceWatcher Uses

type SourceWatcher interface {
    Next() (*ChangeSet, error)
    Stop() error
}

SourceWatcher allows you to watch a source for changes Next is a blocking call which returns the next ChangeSet update. Stop Renders the watcher unusable.

type Value Uses

type Value interface {
    Bool(def bool) bool
    Int(def int) int
    String(def string) string
    Float64(def float64) float64
    Duration(def time.Duration) time.Duration
    StringSlice(def []string) []string
    StringMap(def map[string]string) map[string]string
    Scan(val interface{}) error
    Bytes() []byte
}

Represent a value retrieved from the values loaded

type Values Uses

type Values interface {
    // The path could be a nested structure so
    // make it a composable.
    // Returns internal cached value
    Get(path ...string) Value
    // Sets internal cached value
    Set(val interface{}, path ...string)
    // Deletes internal cached value
    Del(path ...string)
    // Returns vals as bytes
    Bytes() []byte
}

Values loaded within the config

type Watcher Uses

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

Directories

PathSynopsis
protoPackage go_micro_os_config is a generated protocol buffer package.
source/consul
source/etcd
source/file
source/memory
source/os

Package config imports 13 packages (graph) and is imported by 2 packages. Updated 2018-05-27. Refresh now. Tools for package owners.