Documentation
¶
Index ¶
- func ExtractCaptureNames(pattern string) []string
- func ExtractCaptureReferences(targetParameter string) map[string]bool
- func LoadMapperFromFile(layers_ *layers.ParameterLayers, filename string) (middlewares.ConfigMapper, error)
- func NewConfigMapper(layers *layers.ParameterLayers, rules ...MappingRule) (middlewares.ConfigMapper, error)
- func ResolveTargetParameter(targetParameter string, captures map[string]string) (string, error)
- func ValidatePatternSyntax(pattern string) error
- type ConfigMapperBuilder
- func (b *ConfigMapperBuilder) Build() (middlewares.ConfigMapper, error)
- func (b *ConfigMapperBuilder) Map(source string, targetLayer string, targetParameter string, required ...bool) *ConfigMapperBuilder
- func (b *ConfigMapperBuilder) MapObject(parentSource string, targetLayer 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(layers_ *layers.ParameterLayers, filename string) (middlewares.ConfigMapper, error)
LoadMapperFromFile loads a ConfigMapper from a YAML/JSON mapping file using the provided layers.
func NewConfigMapper ¶
func NewConfigMapper(layers *layers.ParameterLayers, rules ...MappingRule) (middlewares.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 parameters exist in their respective layers
- Capture references in target parameters match captures in source patterns
func ResolveTargetParameter ¶
ResolveTargetParameter exposes internal resolveTargetParameter 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(l *layers.ParameterLayers) *ConfigMapperBuilder
NewConfigMapperBuilder creates a new builder for pattern-based mappers.
func (*ConfigMapperBuilder) Build ¶
func (b *ConfigMapperBuilder) Build() (middlewares.ConfigMapper, error)
Build validates rules via NewConfigMapper and returns the resulting ConfigMapper.
func (*ConfigMapperBuilder) Map ¶
func (b *ConfigMapperBuilder) Map(source string, targetLayer string, targetParameter 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, targetLayer 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 layer slug (e.g., "demo")
// If not set in child rules, inherits from parent rule
TargetLayer string
// Target parameter name (supports captures like "{env}-api-key")
// Capture references use the format "{name}" where name is a capture group from Source
TargetParameter 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 layer parameters. A mapping rule specifies:
- Source: Pattern to match in the config file (e.g., "app.settings.api_key", "app.{env}.api_key")
- TargetLayer: Which layer to place the value in
- TargetParameter: Which parameter 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, targetParameter 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.