Documentation
¶
Index ¶
- func ExtractCaptureNames(pattern string) []string
- func ExtractCaptureReferences(targetField string) map[string]bool
- func LoadMapperFromFile(sectionSchema *schema.Schema, filename string) (sources.ConfigMapper, error)
- func NewConfigMapper(sectionSchema *schema.Schema, rules ...MappingRule) (sources.ConfigMapper, error)
- func ResolveTargetField(targetField string, captures map[string]string) (string, error)
- func ValidatePatternSyntax(pattern string) error
- type ConfigMapperBuilder
- func (b *ConfigMapperBuilder) Build() (sources.ConfigMapper, error)
- func (b *ConfigMapperBuilder) Map(source string, targetSection string, targetField string, required ...bool) *ConfigMapperBuilder
- func (b *ConfigMapperBuilder) MapObject(parentSource string, targetSection string, childRules []MappingRule) *ConfigMapperBuilder
- type MappingRule
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ExtractCaptureNames ¶
ExtractCaptureNames exposes internal extractCaptureNames for testing and tooling.
func ExtractCaptureReferences ¶
ExtractCaptureReferences exposes internal extractCaptureReferences for testing and tooling.
func LoadMapperFromFile ¶
func LoadMapperFromFile(sectionSchema *schema.Schema, filename string) (sources.ConfigMapper, error)
LoadMapperFromFile loads a ConfigMapper from a YAML/JSON mapping file using the provided schema.
func NewConfigMapper ¶
func NewConfigMapper(sectionSchema *schema.Schema, rules ...MappingRule) (sources.ConfigMapper, error)
NewConfigMapper creates a new pattern-based config mapper from the given rules. The mapper validates that:
- All patterns are valid syntax
- All target fields exist in their respective sections
- Capture references in target fields match captures in source patterns
func ResolveTargetField ¶
ResolveTargetField exposes internal resolveTargetField for testing and tooling.
func ValidatePatternSyntax ¶
ValidatePatternSyntax exposes internal validatePatternSyntax for testing and tooling.
Types ¶
type ConfigMapperBuilder ¶
type ConfigMapperBuilder struct {
// contains filtered or unexported fields
}
ConfigMapperBuilder provides a fluent API to assemble MappingRules and build a ConfigMapper that reuses NewConfigMapper validation and semantics.
func NewConfigMapperBuilder ¶
func NewConfigMapperBuilder(sectionSchema *schema.Schema) *ConfigMapperBuilder
NewConfigMapperBuilder creates a new builder for pattern-based mappers.
func (*ConfigMapperBuilder) Build ¶
func (b *ConfigMapperBuilder) Build() (sources.ConfigMapper, error)
Build validates rules via NewConfigMapper and returns the resulting ConfigMapper.
func (*ConfigMapperBuilder) Map ¶
func (b *ConfigMapperBuilder) Map(source string, targetSection string, targetField string, required ...bool) *ConfigMapperBuilder
Map adds a simple leaf mapping rule. If required is provided and true, the rule will be marked as Required.
func (*ConfigMapperBuilder) MapObject ¶
func (b *ConfigMapperBuilder) MapObject(parentSource string, targetSection string, childRules []MappingRule) *ConfigMapperBuilder
MapObject adds a parent rule with child rules (one-level nesting supported).
type MappingRule ¶
type MappingRule struct {
// Source path pattern (e.g., "app.settings.api_key", "app.*.key", "app.{env}.api-key")
// Supports:
// - Exact match: "app.settings.api_key"
// - Wildcard: "app.*.api_key" (matches but doesn't capture)
// - Named capture: "app.{env}.api_key" (captures "env")
Source string
// Target section slug (e.g., "demo")
// If not set in child rules, inherits from parent rule
TargetSection string
// Target field name (supports captures like "{env}-api-key")
// Capture references use the format "{name}" where name is a capture group from Source
TargetField string
// Optional: nested rules for mapping child objects
// If provided, Source should point to an object, and Rules maps its children
Rules []MappingRule
// Optional: whether to skip if source doesn't exist (default: false, means skip silently)
// If Required is true, pattern must match or an error is returned
Required bool
}
MappingRule defines a pattern-based mapping from config file structure to section fields. A mapping rule specifies:
- Source: Pattern to match in the config file (e.g., "app.settings.api_key", "app.{env}.api_key")
- TargetSection: Which section to place the value in
- TargetField: Which field name to use (supports capture references like "{env}-api-key")
- Required: Whether the pattern must match (default: false)
- Rules: Optional nested rules for mapping child objects
func Child ¶
func Child(source string, targetField string) MappingRule
Child is a small helper to create a leaf MappingRule for MapObject children.
func LoadRulesFromFile ¶
func LoadRulesFromFile(filename string) ([]MappingRule, error)
LoadRulesFromFile reads YAML/JSON mapping rules from a file path.
func LoadRulesFromReader ¶
func LoadRulesFromReader(r io.Reader) ([]MappingRule, error)
LoadRulesFromReader reads YAML/JSON mapping rules from an io.Reader. It accepts both a top-level object with a "mappings" array and a bare array of rules.