config

package module
v0.0.3 Latest Latest
Warning

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

Go to latest
Published: Jun 26, 2025 License: MIT Imports: 21 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func LoadConfig added in v0.0.2

func LoadConfig[T any](defaults T, flags *pflag.FlagSet, opts ...LoadOption) (*T, error)

Types

type Config

type Config interface {
	Load() error
	Get(key string) Value
	Exists(key string) bool
	Scan(v any) error
	ScanPath(path string, v any) error
	All() map[string]any
	Close() error
}

func NewConfig

func NewConfig(opts ...Option) (Config, error)

type EnvSource added in v0.0.2

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

EnvSource provides environment variable configuration

func NewEnvSource added in v0.0.2

func NewEnvSource(opts ...EnvSourceOption) (*EnvSource, error)

NewEnvSource creates a new EnvSource with the given prefix

func (*EnvSource) Load added in v0.0.2

func (es *EnvSource) Load() (map[string]any, error)

Load returns the configuration data from environment variables

func (*EnvSource) Watch added in v0.0.2

func (es *EnvSource) Watch() (Watcher, error)

type EnvSourceOption added in v0.0.2

type EnvSourceOption func(*EnvSource) error

func WithEnvNameMapping added in v0.0.3

func WithEnvNameMapping(nameMappings map[string]string) EnvSourceOption

WithEnvNameMapping allows setting nameMappings for environment variable names

func WithEnvPrefix added in v0.0.2

func WithEnvPrefix(prefix string) EnvSourceOption

WithEnvPrefix allows setting a prefix for environment variable names

type FileSource added in v0.0.2

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

FileSource provides file-based configuration

func NewFileSource added in v0.0.2

func NewFileSource(opts ...FileSourceOption) (*FileSource, error)

NewFileSource creates a new FileSource with the given files

func (*FileSource) Load added in v0.0.2

func (fs *FileSource) Load() (map[string]any, error)

Load returns the configuration data from files

func (*FileSource) Watch added in v0.0.2

func (fs *FileSource) Watch() (Watcher, error)

type FileSourceOption added in v0.0.2

type FileSourceOption func(*FileSource) error

func WithFilePath added in v0.0.2

func WithFilePath(files ...string) FileSourceOption

type FlagSource added in v0.0.2

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

FlagSource provides command-line flag configuration

func NewFlagSource added in v0.0.2

func NewFlagSource(flags *pflag.FlagSet, opts ...FlagSourceOption) (*FlagSource, error)

NewFlagSource creates a new FlagSource with the given flag set

func (*FlagSource) Load added in v0.0.2

func (fs *FlagSource) Load() (map[string]any, error)

Load returns the configuration data from command-line flags

func (*FlagSource) Watch added in v0.0.2

func (fs *FlagSource) Watch() (Watcher, error)

type FlagSourceOption added in v0.0.2

type FlagSourceOption func(*FlagSource) error

type LoadOption added in v0.0.2

type LoadOption func(*loadOptions)

func WithDefaultValueOptions added in v0.0.2

func WithDefaultValueOptions(defaults any) LoadOption

func WithEnvOptions added in v0.0.2

func WithEnvOptions(opts ...EnvSourceOption) LoadOption

func WithFileOptions added in v0.0.2

func WithFileOptions(opts ...FileSourceOption) LoadOption

func WithFlagOptions added in v0.0.2

func WithFlagOptions(opts ...FlagSourceOption) LoadOption

func WithValueTagOptions added in v0.0.3

func WithValueTagOptions(opts ...ValueSourceOption) LoadOption

type Option

type Option func(*config) error

func WithDelimiter

func WithDelimiter(delim string) Option

func WithSource

func WithSource(sources ...Source) Option

type Source

type Source interface {
	// Load returns the configuration data from this source
	Load() (map[string]any, error)
	Watch() (Watcher, error)
}

Source defines the interface for configuration sources

type Value

type Value interface {
	Bool() (bool, error)
	Int() (int64, error)
	Float() (float64, error)
	String() (string, error)
	Duration() (time.Duration, error)
	Slice() ([]Value, error)
	Map() (map[string]Value, error)
	Scan(any) error
	Load() any
	Store(any)
}

type ValueSource added in v0.0.2

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

ValueSource provides default configuration values

func NewValueSourceFromMap added in v0.0.2

func NewValueSourceFromMap(value map[string]any) (*ValueSource, error)

NewValueSourceFromMap creates a new ValueSource with the given value

func NewValueSourceFromStruct added in v0.0.2

func NewValueSourceFromStruct(defaults any, opts ...ValueSourceOption) (*ValueSource, error)

NewValueSourceFromStruct creates a ValueSource from a struct

func (*ValueSource) Load added in v0.0.2

func (ds *ValueSource) Load() (map[string]any, error)

Load returns the default configuration data

func (*ValueSource) Watch added in v0.0.2

func (ds *ValueSource) Watch() (Watcher, error)

type ValueSourceOption added in v0.0.3

type ValueSourceOption func(*ValueSource) error

func WithValueTag added in v0.0.3

func WithValueTag(tag string) ValueSourceOption

WithValueTag sets the tag used for struct fields in ValueSource

type Watcher

type Watcher interface {
	Next() (map[string]any, error)
	Stop() error
}

Jump to

Keyboard shortcuts

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