configx

package
v0.1.15 Latest Latest
Warning

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

Go to latest
Published: Jun 9, 2024 License: MIT Imports: 31 Imported by: 0

Documentation

Index

Constants

View Source
const (
	FlagConfig = "config"
	Delimiter  = "."
)

Variables

This section is empty.

Functions

func ContextWithConfigOptions

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

func GetAddress

func GetAddress(host string, port int) string

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

func JsonUnmarshalerHookFunc

func JsonUnmarshalerHookFunc() mapstructure.DecodeHookFuncType

func MergeAllTypes

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

func NewImmutableError

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

func RegisterConfigFlag

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

func RegisterFlags

func RegisterFlags(flags *pflag.FlagSet)

RegisterFlags registers the config file flag.

func StringToMailAddressHookFunc

func StringToMailAddressHookFunc() mapstructure.DecodeHookFuncType

func StringToRegexpHookFunc

func StringToRegexpHookFunc() mapstructure.DecodeHookFuncType

func StringToURLHookFunc

func StringToURLHookFunc() mapstructure.DecodeHookFuncType

func TextUnmarshalerHookFunc

func TextUnmarshalerHookFunc() mapstructure.DecodeHookFuncType

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 KoanfConfmap

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

func NewKoanfConfmap

func NewKoanfConfmap(tuples []tuple) *KoanfConfmap

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
}

func NewKoanfFile

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

func NewKoanfFileSubKey

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

func (*KoanfFile) Read

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

func (*KoanfFile) ReadBytes

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

func (*KoanfFile) Watch

func (f *KoanfFile) Watch(cb func(event interface{}, err error)) error

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 NewKoanfMemoryWithParser

func NewKoanfMemoryWithParser(ctx context.Context, doc stdjson.RawMessage, parser koanf.Parser) *KoanfMemory

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 Provider

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

func New

func New(ctx context.Context, options ...ProviderOptions) (*Provider, error)

func (*Provider) BoolF

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

func (*Provider) ByteSizeF

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

func (*Provider) DirtyPatch

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) 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) StringF

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

func (*Provider) StringsF

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

func (*Provider) URIF

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

func (*Provider) Unmarshal

func (p *Provider) Unmarshal(path string, o interface{}) error

func (*Provider) UnmarshalWithConf

func (p *Provider) UnmarshalWithConf(path string, o interface{}, c koanf.UnmarshalConf) error

type ProviderOptions

type ProviderOptions func(p *Provider)

func ConfigOptionsFromContext

func ConfigOptionsFromContext(ctx context.Context) []ProviderOptions

func DisabledEnvLoading

func DisabledEnvLoading() ProviderOptions

DisabledEnvLoading disables env loading. Notes: cant be used with EnableEnvLoading at the same time

func EnableEnvLoading

func EnableEnvLoading(prefix string) ProviderOptions

EnableEnvLoading enables env loading. Notes: cant be used with DisabledEnvLoading at the same time

func WithBaseValues

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

func WithChangeNotifier

func WithChangeNotifier(notifier func(event interface{}, err error)) ProviderOptions

func WithConfigFiles

func WithConfigFiles(files ...string) ProviderOptions

func WithContext

func WithContext(ctx context.Context) ProviderOptions

func WithDecodeHookFunc

func WithDecodeHookFunc(decodeHookFunc mapstructure.DecodeHookFunc) ProviderOptions

func WithExceptImmutables

func WithExceptImmutables(exceptImmutables ...string) ProviderOptions

func WithFlags

func WithFlags(flags *pflag.FlagSet) ProviderOptions

func WithImmutables

func WithImmutables(immutables ...string) ProviderOptions

func WithLogger

func WithLogger(l *slog.Logger) ProviderOptions

func WithUserProviders

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

func WithValue

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

func WithValues

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

Jump to

Keyboard shortcuts

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