Documentation
¶
Overview ¶
Package config provides configuration loading, schema validation, fallback resolution, and automatic repair.
Index ¶
- func GenerateExample(schema *SchemaNode) string
- func GetZeroValueByType(kind reflect.Kind) any
- func GetZeroValueString(kind reflect.Kind) string
- func Load[T any](path string, opts ...Option) (*T, error)
- func ParseDefaultToType(val string, kind reflect.Kind, elemKind reflect.Kind) any
- func RepairTOMLFile(path string, schema *SchemaNode) (bool, error)
- func SetDefaultsRecursive(cfg any) error
- func ValidateRecursive(cfg any) error
- type Defaulter
- type FallbackResolver
- type Option
- type Options
- type SchemaField
- type SchemaNode
- type Validator
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func GenerateExample ¶
func GenerateExample(schema *SchemaNode) string
func GetZeroValueByType ¶
func GetZeroValueString ¶
func Load ¶
Load reads and parses a configuration struct from TOML and environment variables, applying defaults, fallbacks, and validation rules.
func ParseDefaultToType ¶
func RepairTOMLFile ¶
func RepairTOMLFile(path string, schema *SchemaNode) (bool, error)
func SetDefaultsRecursive ¶
SetDefaultsRecursive traverses the configuration tree and invokes SetDefaults on all applicable nodes.
func ValidateRecursive ¶
ValidateRecursive traverses the configuration tree and validates all nodes implementing Validator.
Types ¶
type Defaulter ¶
type Defaulter interface {
SetDefaults()
}
Defaulter enables a configuration struct to set dynamic defaults or normalize values.
type FallbackResolver ¶
type FallbackResolver struct {
// contains filtered or unexported fields
}
func NewFallbackResolver ¶
func NewFallbackResolver(root reflect.Value) (*FallbackResolver, error)
func (*FallbackResolver) Resolve ¶
func (r *FallbackResolver) Resolve() error
type Option ¶
type Option func(*Options)
Option configures loader behavior.
func WithAutoRepair ¶
WithAutoRepair configures whether missing configuration fields are automatically written to disk.
func WithLogger ¶
WithLogger configures a custom writer for loader diagnostic messages.
type SchemaField ¶
type SchemaField struct {
Path string
Key string
DefaultVal string
Comment string
Fallback string
IsRequired bool
Kind reflect.Kind
ElemKind reflect.Kind
}
SchemaField represents metadata for a single configuration field.
type SchemaNode ¶
type SchemaNode struct {
Section string
Fields []SchemaField
Children map[string]*SchemaNode
}
SchemaNode represents a hierarchical node within the configuration structure.
func BuildSchema ¶
func BuildSchema(t reflect.Type, currentSection string) (*SchemaNode, error)
BuildSchema inspects a struct type and constructs a SchemaNode tree.