const ( FlagConfig = "config" Delimiter = "." )
const ( LoadSpanOpName = "config-load" UpdatedSpanOpName = "config-update" SnapshotSpanOpName = "config-snapshot" )
func ContextWithConfigOptions(ctx context.Context, opts ...OptionModifier) context.Context
func LogrusWatcher(l *logrusx.Logger) func(e watcherx.Event, err error)
func NewImmutableError(key string, from, to interface{}) error
func NewKoanfEnv(prefix string, schema []byte) (*env.Env, error)
func RegisterConfigFlag(flags *pflag.FlagSet, fallback []string)
RegisterConfigFlag registers the "--config" flag on pflag.FlagSet.
func RegisterFlags(flags *pflag.FlagSet)
RegisterFlags registers the config file flag.
type ImmutableError struct { From interface{} To interface{} Key string // contains filtered or unexported fields }
func (e *ImmutableError) Error() string
KoanfConfmap implements a raw map[string]interface{} provider.
type KoanfConfmap struct {
// contains filtered or unexported fields
}
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 (e *KoanfConfmap) Read() (map[string]interface{}, error)
Read returns the loaded map[string]interface{}.
func (e *KoanfConfmap) ReadBytes() ([]byte, error)
ReadBytes is not supported by the env provider.
KoanfFile implements a KoanfFile provider.
type KoanfFile struct {
// contains filtered or unexported fields
}
func NewKoanfFile(ctx context.Context, path string) (*KoanfFile, error)
Provider returns a file provider.
func NewKoanfFileSubKey(ctx context.Context, path, subKey string) (*KoanfFile, error)
func (f *KoanfFile) Read() (map[string]interface{}, error)
Read is not supported by the file provider.
func (f *KoanfFile) ReadBytes() ([]byte, error)
ReadBytes reads the contents of a file on disk and returns the bytes.
func (f *KoanfFile) WatchChannel(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 KoanfSchemaDefaults struct {
// contains filtered or unexported fields
}
func NewKoanfSchemaDefaults(schema []byte) (*KoanfSchemaDefaults, error)
func (k *KoanfSchemaDefaults) Read() (map[string]interface{}, error)
func (k *KoanfSchemaDefaults) ReadBytes() ([]byte, error)
type OptionModifier func(p *Provider)
func AttachWatcher(watcher func(event watcherx.Event, err error)) OptionModifier
func ConfigOptionsFromContext(ctx context.Context) []OptionModifier
func OmitKeysFromTracing(keys ...string) OptionModifier
func SkipValidation() OptionModifier
func WithBaseValues(values map[string]interface{}) OptionModifier
func WithConfigFiles(files ...string) OptionModifier
func WithContext(ctx context.Context) OptionModifier
func WithFlags(flags *pflag.FlagSet) OptionModifier
func WithImmutables(immutables ...string) OptionModifier
func WithLogger(l *logrusx.Logger) OptionModifier
func WithLogrusWatcher(l *logrusx.Logger) OptionModifier
func WithStandardValidationReporter(w io.Writer) OptionModifier
func WithStderrValidationReporter() OptionModifier
func WithValue(key string, value interface{}) OptionModifier
func WithValues(values map[string]interface{}) OptionModifier
type Provider struct { *koanf.Koanf // contains filtered or unexported fields }
func New(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
func (p *Provider) BoolF(key string, fallback bool) bool
func (p *Provider) ByteSizeF(key string, fallback bytesize.ByteSize) bytesize.ByteSize
func (p *Provider) CORS(prefix string, defaults cors.Options) (cors.Options, bool)
func (p *Provider) DurationF(key string, fallback time.Duration) (val time.Duration)
func (p *Provider) Float64F(key string, fallback float64) (val float64)
func (p *Provider) GetF(key string, fallback interface{}) (val interface{})
func (p *Provider) IntF(key string, fallback int) (val int)
func (p *Provider) PrintHumanReadableValidationErrors(w io.Writer, err error)
PrintHumanReadableValidationErrors prints human readable validation errors. Duh.
func (p *Provider) RequestURIF(path string, fallback *url.URL) *url.URL
func (p *Provider) Set(key string, value interface{}) error
func (p *Provider) SetTracer(ctx context.Context, t *tracing.Tracer)
TraceSnapshot will send the configuration to the tracer.
func (p *Provider) StringF(key string, fallback string) string
func (p *Provider) StringsF(key string, fallback []string) (val []string)
func (p *Provider) TracingConfig(serviceName string) *tracing.Config
func (p *Provider) URIF(path string, fallback *url.URL) *url.URL