configx

package
v0.0.628 Latest Latest
Warning

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

Go to latest
Published: Apr 19, 2024 License: Apache-2.0 Imports: 41 Imported by: 37

Documentation

Index

Constants

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

Variables

This section is empty.

Functions

func ContextWithConfigOptions added in v0.0.172

func ContextWithConfigOptions(ctx context.Context, opts ...OptionModifier) context.Context

func GetAddress added in v0.0.221

func GetAddress(host string, port int) string

host = unix:/path/to/socket => port is discarded, otherwise format as host:port

func LogrusWatcher

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

func MergeAllTypes added in v0.0.328

func MergeAllTypes(src, dst map[string]interface{}) error

func NewImmutableError

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

func RegisterConfigFlag added in v0.0.167

func RegisterConfigFlag(flags *pflag.FlagSet, fallback []string)

RegisterConfigFlag registers the "--config" flag on pflag.FlagSet.

func RegisterFlags

func RegisterFlags(flags *pflag.FlagSet)

RegisterFlags registers the config file flag.

Types

type Env added in v0.0.328

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

Env implements an environment variables provider.

func NewKoanfEnv

func NewKoanfEnv(prefix string, rawSchema []byte, schema *jsonschema.Schema) (*Env, error)

func (*Env) Read added in v0.0.328

func (e *Env) Read() (map[string]interface{}, error)

Read reads all available environment variables into a key:value map and returns it.

func (*Env) ReadBytes added in v0.0.328

func (e *Env) ReadBytes() ([]byte, error)

ReadBytes is not supported by the env provider.

func (*Env) Watch added in v0.0.328

func (e *Env) Watch(cb func(event interface{}, err error)) error

Watch is not supported.

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 KoanfConfmap added in v0.0.170

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

KoanfConfmap implements a raw map[string]interface{} provider.

func NewKoanfConfmap added in v0.0.170

func NewKoanfConfmap(tuples []tuple) *KoanfConfmap

Provider returns a confmap Provider that takes a flat or nested map[string]interface{}. If a delim is provided, it indicates that the keys are flat and the map needs to be unflatted by delim.

func (*KoanfConfmap) Read added in v0.0.170

func (e *KoanfConfmap) Read() (map[string]interface{}, error)

Read returns the loaded map[string]interface{}.

func (*KoanfConfmap) ReadBytes added in v0.0.170

func (e *KoanfConfmap) ReadBytes() ([]byte, error)

ReadBytes is not supported by the env provider.

type KoanfFile

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

KoanfFile implements a KoanfFile provider.

func NewKoanfFile

func NewKoanfFile(path string) (*KoanfFile, error)

NewKoanfFile returns a file provider.

func NewKoanfFileSubKey added in v0.0.167

func NewKoanfFileSubKey(path, subKey string) (*KoanfFile, error)

func (*KoanfFile) Read

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

Read reads the file and returns the parsed configuration.

func (*KoanfFile) ReadBytes

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

ReadBytes is not supported by KoanfFile.

func (*KoanfFile) WatchChannel

func (f *KoanfFile) WatchChannel(ctx context.Context, c watcherx.EventChannel) (watcherx.Watcher, 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 KoanfMemory added in v0.0.247

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

KoanfMemory implements a KoanfMemory provider.

func NewKoanfMemory added in v0.0.247

func NewKoanfMemory(ctx context.Context, doc stdjson.RawMessage) *KoanfMemory

NewKoanfMemory returns a file provider.

func (*KoanfMemory) Read added in v0.0.247

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

Read is not supported by the file provider.

func (*KoanfMemory) ReadBytes added in v0.0.247

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

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

func (*KoanfMemory) SetDoc added in v0.0.247

func (f *KoanfMemory) SetDoc(doc stdjson.RawMessage)

type KoanfSchemaDefaults

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

func NewKoanfSchemaDefaults

func NewKoanfSchemaDefaults(rawSchema []byte, schema *jsonschema.Schema) (*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 ConfigOptionsFromContext added in v0.0.172

func ConfigOptionsFromContext(ctx context.Context) []OptionModifier

func DisableEnvLoading added in v0.0.345

func DisableEnvLoading() OptionModifier

func OmitKeysFromTracing

func OmitKeysFromTracing(keys ...string) OptionModifier

func SkipValidation added in v0.0.170

func SkipValidation() OptionModifier

func WithBaseValues added in v0.0.183

func WithBaseValues(values map[string]interface{}) OptionModifier

func WithConfigFiles added in v0.0.170

func WithConfigFiles(files ...string) OptionModifier

func WithContext

func WithContext(ctx context.Context) OptionModifier

func WithExceptImmutables added in v0.0.578

func WithExceptImmutables(exceptImmutables ...string) OptionModifier

func WithFlags added in v0.0.170

func WithFlags(flags *pflag.FlagSet) OptionModifier

func WithImmutables

func WithImmutables(immutables ...string) OptionModifier

func WithLogger added in v0.0.176

func WithLogger(l *logrusx.Logger) OptionModifier

func WithLogrusWatcher

func WithLogrusWatcher(l *logrusx.Logger) OptionModifier

func WithStandardValidationReporter

func WithStandardValidationReporter(w io.Writer) OptionModifier

func WithStderrValidationReporter

func WithStderrValidationReporter() OptionModifier

func WithUserProviders added in v0.0.247

func WithUserProviders(providers ...koanf.Provider) OptionModifier

func WithValue added in v0.0.170

func WithValue(key string, value interface{}) OptionModifier

func WithValues added in v0.0.170

func WithValues(values map[string]interface{}) OptionModifier

type PFlagProvider added in v0.0.352

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

func NewPFlagProvider added in v0.0.352

func NewPFlagProvider(rawSchema []byte, schema *jsonschema.Schema, f *pflag.FlagSet, k *koanf.Koanf) (*PFlagProvider, error)

func (*PFlagProvider) Read added in v0.0.352

func (p *PFlagProvider) Read() (map[string]interface{}, error)

func (*PFlagProvider) ReadBytes added in v0.0.352

func (p *PFlagProvider) ReadBytes() ([]byte, error)

type Provider

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

func New

func New(ctx context.Context, schema []byte, 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

There will also be file-watchers started for all config files. To cancel the watchers, cancel the context.

func (*Provider) BoolF

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

func (*Provider) ByteSizeF added in v0.0.176

func (p *Provider) ByteSizeF(key string, fallback bytesize.ByteSize) bytesize.ByteSize

func (*Provider) CORS

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

func (*Provider) DirtyPatch added in v0.0.585

func (p *Provider) DirtyPatch(key string, value any) error

DirtyPatch patches individual config keys without reloading the full config

WARNING! This method is only useful to override existing keys in string or number format. DO NOT use this method to override arrays, maps, or other complex types.

This method DOES NOT validate the config against the config JSON schema. If you need to validate the config, use the Set method instead.

This method can not be used to remove keys from the config as that is not possible without reloading the full config.

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{}) error

func (*Provider) SetTracer

func (p *Provider) SetTracer(_ context.Context, _ *otelx.Tracer)

SetTracer does nothing. DEPRECATED without replacement.

func (*Provider) SkipValidation added in v0.0.285

func (p *Provider) SkipValidation() bool

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) *otelx.Config

func (*Provider) URIF

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

type UnixPermission added in v0.0.221

type UnixPermission struct {
	Owner string
	Group string
	Mode  os.FileMode
}

func (*UnixPermission) SetPermission added in v0.0.221

func (p *UnixPermission) SetPermission(file string) error

Jump to

Keyboard shortcuts

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