Documentation
¶
Index ¶
- Variables
- type Config
- func (c *Config) Bind(instance any) error
- func (c *Config) BindWithDefaults(instance any) error
- func (c *Config) Export(path string) error
- func (c *Config) Get(key string) any
- func (c *Config) Restore(snapshot map[string]any) error
- func (c *Config) Set(key string, value any)
- func (c *Config) Snapshot() (map[string]any, error)
- func (c *Config) Validate() error
- func (c *Config) ValidateType(instance any) error
- type ConfigInterface
- type Event
- type EventOp
- type FileType
- type Option
- func WithDotEnv(path string) Option
- func WithDotEnvAuto(dir ...string) Option
- func WithEncryption(algo string, key []byte) Option
- func WithEnvPrefix(prefix string) Option
- func WithFile(name string) Option
- func WithFileType(ft FileType) Option
- func WithLoadAll(enable bool) Option
- func WithOnChange(fn func(Event)) Option
- func WithPath(path string) Option
- func WithWatch(enable bool) Option
- type Validator
Constants ¶
This section is empty.
Variables ¶
var ( ErrNilConfig = errors.New("confy: config instance is nil") ErrNilTarget = errors.New("confy: target instance is nil") ErrNoConfigFiles = errors.New("confy: no valid configuration files found") ErrNoSnapshot = errors.New("confy: no snapshot available to restore") ErrNilSnapshot = errors.New("confy: snapshot is nil") ErrEmptyExportPath = errors.New("confy: export path is empty") ErrMustBeStruct = errors.New("confy: config must be a struct") ErrCycleDetected = errors.New("confy: circular base inheritance detected") )
Functions ¶
This section is empty.
Types ¶
type Config ¶
type Config struct {
// contains filtered or unexported fields
}
Config is the main configuration instance.
func (*Config) Bind ¶
Bind unmarshals the config into the target struct. If watching is enabled, the target will be automatically updated on config changes.
func (*Config) BindWithDefaults ¶
BindWithDefaults applies struct default values before and after binding.
func (*Config) Validate ¶
Validate checks if the bound config implements the Validator interface and calls it.
func (*Config) ValidateType ¶
ValidateType checks struct fields with `required:"true"` are non-zero, and validates type compatibility via mapstructure tags.
type ConfigInterface ¶
type ConfigInterface interface {
Bind(instance any) error
BindWithDefaults(instance any) error
Validate() error
ValidateType(instance any) error
Export(path string) error
Snapshot() (map[string]any, error)
Restore() error
Get(key string) any
Set(key string, value any)
}
ConfigInterface defines the public contract for a Config instance.
type Option ¶
type Option func(*configOptions)
Option is a function that configures a configOptions instance.
func WithDotEnvAuto ¶
WithDotEnvAuto enables automatic .env file discovery based on environment mode. It discovers and loads .env files in priority order: .env → .env.local → .env.{env} → .env.{env}.local The dir parameter specifies the directory to search in (defaults to "." if empty).
func WithEncryption ¶
WithEncryption enables config value encryption/decryption.
func WithEnvPrefix ¶
WithEnvPrefix sets the environment variable prefix.
func WithFileType ¶
WithFileType sets the default config file format.
func WithLoadAll ¶
WithLoadAll enables loading all config files in the directory.
func WithOnChange ¶
WithOnChange sets the callback for config file changes.