configx

package
v0.0.166 Latest Latest
Warning

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

Go to latest
Published: Dec 1, 2020 License: Apache-2.0 Imports: 36 Imported by: 41

Documentation

Index

Constants

View Source
const (
	LoadSpanOpName     = "config-load"
	UpdatedSpanOpName  = "config-update"
	SnapshotSpanOpName = "config-snapshot"
)

Variables

This section is empty.

Functions

func LogrusWatcher

func LogrusWatcher(l *logrusx.Logger) func(e watcherx.Event, err error)

func NewImmutableError

func NewImmutableError(key string, from, to interface{}) error

func NewKoanfEnv

func NewKoanfEnv(prefix string, schema []byte) (*env.Env, error)

func RegisterFlags

func RegisterFlags(flags *pflag.FlagSet)

RegisterFlags registers the config file flag.

Types

type ImmutableError

type ImmutableError struct {
	From interface{}
	To   interface{}
	Key  string
	// contains filtered or unexported fields
}

func (*ImmutableError) Error

func (e *ImmutableError) Error() string

type KoanfFile

type KoanfFile struct {
	// contains filtered or unexported fields
}

KoanfFile implements a KoanfFile provider.

func NewKoanfFile

func NewKoanfFile(ctx context.Context, path string) *KoanfFile

Provider returns a file provider.

func (*KoanfFile) Read

func (f *KoanfFile) Read() (map[string]interface{}, error)

Read is not supported by the file provider.

func (*KoanfFile) ReadBytes

func (f *KoanfFile) ReadBytes() ([]byte, error)

ReadBytes reads the contents of a file on disk and returns the bytes.

func (*KoanfFile) WatchChannel

func (f *KoanfFile) WatchChannel(c watcherx.EventChannel) error

WatchChannel watches the file and triggers a callback when it changes. It is a blocking function that internally spawns a goroutine to watch for changes.

type KoanfSchemaDefaults

type KoanfSchemaDefaults struct {
	// contains filtered or unexported fields
}

func NewKoanfSchemaDefaults

func NewKoanfSchemaDefaults(schema []byte) (*KoanfSchemaDefaults, error)

func (*KoanfSchemaDefaults) Read

func (k *KoanfSchemaDefaults) Read() (map[string]interface{}, error)

func (*KoanfSchemaDefaults) ReadBytes

func (k *KoanfSchemaDefaults) ReadBytes() ([]byte, error)

type OptionModifier

type OptionModifier func(p *Provider)

func AttachWatcher

func AttachWatcher(watcher func(event watcherx.Event, err error)) OptionModifier

func OmitKeysFromTracing

func OmitKeysFromTracing(keys []string) OptionModifier

func WithContext

func WithContext(ctx context.Context) OptionModifier

func WithImmutables

func WithImmutables(immutables []string) OptionModifier

func WithLogrusWatcher

func WithLogrusWatcher(l *logrusx.Logger) OptionModifier

func WithStandardValidationReporter

func WithStandardValidationReporter(w io.Writer) OptionModifier

func WithStderrValidationReporter

func WithStderrValidationReporter() OptionModifier

type Provider

type Provider struct {
	*koanf.Koanf
	// contains filtered or unexported fields
}

func New

func New(schema []byte, flags *pflag.FlagSet, modifiers ...OptionModifier) (*Provider, error)

New creates a new provider instance or errors. Configuration values are loaded in the following order:

1. Defaults from the JSON Schema 2. Config files (yaml, yml, toml, json) 3. Command line flags 4. Environment variables

func (*Provider) BoolF

func (p *Provider) BoolF(key string, fallback bool) bool

func (*Provider) CORS

func (p *Provider) CORS(prefix string, defaults cors.Options) (cors.Options, bool)

func (*Provider) DurationF

func (p *Provider) DurationF(key string, fallback time.Duration) (val time.Duration)

func (*Provider) Float64F

func (p *Provider) Float64F(key string, fallback float64) (val float64)

func (*Provider) GetF

func (p *Provider) GetF(key string, fallback interface{}) (val interface{})

func (*Provider) IntF

func (p *Provider) IntF(key string, fallback int) (val int)

func (*Provider) PrintHumanReadableValidationErrors

func (p *Provider) PrintHumanReadableValidationErrors(w io.Writer, err error)

PrintHumanReadableValidationErrors prints human readable validation errors. Duh.

func (*Provider) RequestURIF

func (p *Provider) RequestURIF(path string, fallback *url.URL) *url.URL

func (*Provider) Set

func (p *Provider) Set(key string, value interface{})

func (*Provider) SetTracer

func (p *Provider) SetTracer(ctx context.Context, t *tracing.Tracer)

TraceSnapshot will send the configuration to the tracer.

func (*Provider) StringF

func (p *Provider) StringF(key string, fallback string) string

func (*Provider) StringsF

func (p *Provider) StringsF(key string, fallback []string) (val []string)

func (*Provider) TracingConfig

func (p *Provider) TracingConfig(serviceName string) *tracing.Config

func (*Provider) URIF

func (p *Provider) URIF(path string, fallback *url.URL) *url.URL

Jump to

Keyboard shortcuts

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