Documentation ¶
Index ¶
- Constants
- func ContextWithConfigOptions(ctx context.Context, opts ...OptionModifier) context.Context
- func GetAddress(host string, port int) string
- func LogrusWatcher(l *logrusx.Logger) func(e watcherx.Event, err error)
- func MergeAllTypes(src, dst map[string]interface{}) error
- func NewImmutableError(key string, from, to interface{}) error
- func RegisterConfigFlag(flags *pflag.FlagSet, fallback []string)
- func RegisterFlags(flags *pflag.FlagSet)
- type Env
- type ImmutableError
- type KoanfConfmap
- type KoanfFile
- type KoanfMemory
- type KoanfSchemaDefaults
- type OptionModifier
- func AttachWatcher(watcher func(event watcherx.Event, err error)) OptionModifier
- func ConfigOptionsFromContext(ctx context.Context) []OptionModifier
- func DisableEnvLoading() 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 WithUserProviders(providers ...koanf.Provider) OptionModifier
- func WithValue(key string, value interface{}) OptionModifier
- func WithValues(values map[string]interface{}) OptionModifier
- type PFlagProvider
- type Provider
- 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) Close()
- 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) MeterConfig(serviceName string, attrs ...attribute.KeyValue) *otelx.MeterConfig
- func (p *Provider) PrintHumanReadableValidationErrors(w io.Writer, err error)
- func (p *Provider) PubSubConfig() *pubsubx.Config
- func (p *Provider) RequestURIF(path string, fallback *url.URL) *url.URL
- func (p *Provider) Set(key string, value interface{}) error
- func (p *Provider) SetTracer(_ context.Context, t *otelx.Tracer)
- func (p *Provider) SkipValidation() bool
- func (p *Provider) StringF(key string, fallback string) string
- func (p *Provider) StringsF(key string, fallback []string) (val []string)
- func (p *Provider) TracerConfig(serviceName string, attrs ...attribute.KeyValue) *otelx.TracerConfig
- func (p *Provider) URIF(path string, fallback *url.URL) *url.URL
- type UnixPermission
Constants ¶
const ( FlagConfig = "config" Delimiter = "." )
const ( LoadSpanOpName = "config-load" UpdatedSpanOpName = "config-update" SnapshotSpanOpName = "config-snapshot" )
Variables ¶
This section is empty.
Functions ¶
func ContextWithConfigOptions ¶
func ContextWithConfigOptions(ctx context.Context, opts ...OptionModifier) context.Context
func GetAddress ¶
host = unix:/path/to/socket => port is discarded, otherwise format as host:port
func MergeAllTypes ¶
func NewImmutableError ¶
func RegisterConfigFlag ¶
RegisterConfigFlag registers the "--config" flag on pflag.FlagSet.
func RegisterFlags ¶
RegisterFlags registers the config file flag.
Types ¶
type Env ¶
type Env struct {
// contains filtered or unexported fields
}
Env implements an environment variables provider.
func NewKoanfEnv ¶
func (*Env) Read ¶
Read reads all available environment variables into a key:value map and returns it.
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 ¶
type KoanfConfmap struct {
// contains filtered or unexported fields
}
KoanfConfmap implements a raw map[string]interface{} provider.
func NewKoanfConfmap ¶
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 ¶
func (e *KoanfConfmap) Read() (map[string]interface{}, error)
Read returns the loaded map[string]interface{}.
func (*KoanfConfmap) ReadBytes ¶
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 ¶
Provider returns a file provider.
func NewKoanfFileSubKey ¶
func (*KoanfFile) WatchChannel ¶
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 ¶
type KoanfMemory struct {
// contains filtered or unexported fields
}
KoanfMemory implements a KoanfMemory provider.
func NewKoanfMemory ¶
func NewKoanfMemory(ctx context.Context, doc stdjson.RawMessage) *KoanfMemory
NewKoanfMemory returns a file provider.
func (*KoanfMemory) Read ¶
func (f *KoanfMemory) Read() (map[string]interface{}, error)
Read is not supported by the file provider.
func (*KoanfMemory) ReadBytes ¶
func (f *KoanfMemory) ReadBytes() ([]byte, error)
ReadBytes reads the contents of a file on disk and returns the bytes.
func (*KoanfMemory) SetDoc ¶
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 ¶
func ConfigOptionsFromContext(ctx context.Context) []OptionModifier
func DisableEnvLoading ¶
func DisableEnvLoading() OptionModifier
func OmitKeysFromTracing ¶
func OmitKeysFromTracing(keys ...string) OptionModifier
func SkipValidation ¶
func SkipValidation() OptionModifier
func WithBaseValues ¶
func WithBaseValues(values map[string]interface{}) OptionModifier
func WithConfigFiles ¶
func WithConfigFiles(files ...string) OptionModifier
func WithContext ¶
func WithContext(ctx context.Context) OptionModifier
func WithFlags ¶
func WithFlags(flags *pflag.FlagSet) OptionModifier
func WithImmutables ¶
func WithImmutables(immutables ...string) OptionModifier
func WithLogger ¶
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 ¶
func WithUserProviders(providers ...koanf.Provider) OptionModifier
func WithValue ¶
func WithValue(key string, value interface{}) OptionModifier
func WithValues ¶
func WithValues(values map[string]interface{}) OptionModifier
type PFlagProvider ¶
type PFlagProvider struct {
// contains filtered or unexported fields
}
func NewPFlagProvider ¶
func (*PFlagProvider) Read ¶
func (p *PFlagProvider) Read() (map[string]interface{}, error)
func (*PFlagProvider) ReadBytes ¶
func (p *PFlagProvider) ReadBytes() ([]byte, error)
type Provider ¶
func New ¶
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
ctx is used for cancelation in case a schema is loaded from a URL. Background reloading of files is enabled automatically. Call Close on the returned Provider to stop the background reloading.
func (*Provider) MeterConfig ¶ added in v0.0.36
func (*Provider) PrintHumanReadableValidationErrors ¶
PrintHumanReadableValidationErrors prints human readable validation errors. Duh.
func (*Provider) PubSubConfig ¶ added in v0.0.11
func (*Provider) RequestURIF ¶
func (*Provider) SkipValidation ¶
func (*Provider) TracerConfig ¶ added in v0.0.33
type UnixPermission ¶
func (*UnixPermission) SetPermission ¶
func (p *UnixPermission) SetPermission(file string) error