koanfx

package
v0.0.13 Latest Latest
Warning

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

Go to latest
Published: Jun 11, 2025 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewDefaultUnmarshalConfig

func NewDefaultUnmarshalConfig() koanf.UnmarshalConf

NewDefaultUnmarshalConfig creates a new default UnmarshalConf with the default tag.

func NewUnmarshalConfig

func NewUnmarshalConfig() koanf.UnmarshalConf

NewUnmarshalConfig creates a new UnmarshalConf with the default decoder config.

func Unmarshal

func Unmarshal(koanf *koanf.Koanf, key string, destination any, opts ...Option) error

Unmarshal unmarshals with optional additional options, starting from the provided key.

func UnmarshalAll

func UnmarshalAll(koanf *koanf.Koanf, destination any, opts ...Option) error

UnmarshalAll unmarshals all keys from the Koanf instance into the provided struct.

func UnmarshalAllWithMetadata

func UnmarshalAllWithMetadata(koanf *koanf.Koanf, destination any, opts ...Option) (mapstructure.Metadata, error)

UnmarshalAllWithMetadata unmarshals all keys from the Koanf instance into the provided struct and returns metadata.

func UnmarshalWithMetadata

func UnmarshalWithMetadata(
	koanf *koanf.Koanf,
	key string,
	destination any,
	opts ...Option,
) (mapstructure.Metadata, error)

UnmarshalWithMetadata unmarshals with metadata and optional additional options, starting from the provided key.

Types

type Koanf

type Koanf struct {
	*koanf.Koanf

	Tracker *Tracker
	// contains filtered or unexported fields
}

Koanf is a wrapper around koanf.Koanf that tracks the keys that have been set.

func FromStruct

func FromStruct(data any, tag string) (*Koanf, error)

FromStruct creates a new Koanf instance from a struct, loading the struct's fields into the koanf.Koanf instance.

func New

func New() *Koanf

New creates a new Koanf instance with a new koanf.Koanf instance.

func (*Koanf) ClearTracker

func (kwt *Koanf) ClearTracker() *Koanf

ClearTracker overwrites the Tracker in the Koanf instance with a fresh Tracker instance.

func (*Koanf) Filtered

func (kwt *Koanf) Filtered(keys ...string) *Koanf

Filtered returns a new Koanf instance that only contains the specified keys. Any keys that don't exist in the original instance are ignored.

func (*Koanf) IsSet

func (kwt *Koanf) IsSet(key string) bool

IsSet checks if a key is set in the Koanf instance.

func (*Koanf) Load

func (kwt *Koanf) Load(p koanf.Provider, pa koanf.Parser, opts ...koanf.Option) error

Load loads configuration from a provider and tracks the source.

func (*Koanf) Map

func (kwt *Koanf) Map() map[string]any

Map returns the koanf instance as a map.

func (*Koanf) Track

func (kwt *Koanf) Track() *Koanf

Track sets the active tracking function to the last one set.

func (*Koanf) TrackAll

func (kwt *Koanf) TrackAll() *Koanf

TrackAll tracks all keys from the koanf instance.

func (*Koanf) TrackFlags

func (kwt *Koanf) TrackFlags() *Koanf

TrackFlags tracks changed flags from a FlagSet.

func (*Koanf) Unmarshal

func (kwt *Koanf) Unmarshal(destination any, opts ...Option) error

Unmarshal unmarshals the configuration into the provided struct.

func (*Koanf) UnmarshalWithMetadata

func (kwt *Koanf) UnmarshalWithMetadata(destination any, opts ...Option) (mapstructure.Metadata, error)

UnmarshalWithMetadata unmarshals the configuration into the provided struct and returns metadata.

func (*Koanf) WithFlags

func (kwt *Koanf) WithFlags(newF *pflag.FlagSet) *Koanf

WithFlags overwrites the flags in the Koanf instance with a new pflag.FlagSet.

func (*Koanf) WithKoanf

func (kwt *Koanf) WithKoanf(newK *koanf.Koanf) *Koanf

WithKoanf overwrites the Koanf in the Koanf instance with a new koanf.Koanf instance.

type Option

type Option func(*koanf.UnmarshalConf)

Option is a function that modifies an UnmarshalConf.

func WithErrorUnused

func WithErrorUnused() Option

WithErrorUnused causes errors on unused fields.

func WithFlatPaths

func WithFlatPaths() Option

WithFlatPaths enables flat paths.

func WithSquash

func WithSquash() Option

WithSquash enables squash.

type SetMap

type SetMap map[string]bool

SetMap is a map that tracks the keys that have been set and whether they were changed.

type Tracker

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

Tracker is a structure that tracks the keys in a koanf instance and their changed status.

func NewTracker

func NewTracker() *Tracker

NewTracker creates a new Tracker instance.

func (*Tracker) Exists

func (dt *Tracker) Exists(key string) bool

Exists checks if a key exists in the tracker.

func (*Tracker) IsSet

func (dt *Tracker) IsSet(key string) bool

IsSet checks if a key is set in the tracker.

func (*Tracker) Names

func (dt *Tracker) Names() []string

Names returns the names of all tracked keys.

func (*Tracker) TrackAll

func (dt *Tracker) TrackAll(k *koanf.Koanf)

TrackAll tracks all keys from the koanf instance.

func (*Tracker) TrackFlags

func (dt *Tracker) TrackFlags(flags *pflag.FlagSet)

TrackFlags tracks changed flags from a FlagSet.

Jump to

Keyboard shortcuts

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