Documentation
¶
Index ¶
- func Decode(resolver TypeResolver, source map[string]any, output any) error
- func UnmarshalJSON(resolver TypeResolver, data []byte, output any) error
- type Polymorphism
- type PolymorphismBuilderBase
- type PolymorphismBuilderDiscriminatorKeyDefiner
- type PolymorphismBuilderEmpty
- type PolymorphismBuilderFinalizer
- type PolymorphismBuilderRuleAdder
- type PolymorphismBuilderStrategySelector
- type PolymorphismRuleBuilder
- type PolymorphismTypeMapBuilder
- type Rule
- type RuleBuilder
- func (b *RuleBuilder) Build() ([]error, Rule)
- func (b *RuleBuilder) IsEqualTo(value any) RuleBuilderTypeAssigner
- func (b *RuleBuilder) Matches(comparator func(any) bool) RuleBuilderTypeAssigner
- func (b *RuleBuilder) ThenAssignType(newType reflect.Type) RuleBuilderFinalizer
- func (b *RuleBuilder) WhenValueAt(valuePath objectpath.ObjectPath) RuleBuilderConditionSetter
- func (b *RuleBuilder) WhenValueAtPathString(valuePath string) RuleBuilderConditionSetter
- type RuleBuilderBase
- type RuleBuilderConditionSetter
- type RuleBuilderFinalizer
- type RuleBuilderTypeAssigner
- type RulePolymorphism
- type TypeMap
- type TypeMapPolymorphism
- type TypeResolver
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Decode ¶
func Decode(resolver TypeResolver, source map[string]any, output any) error
Decode decodes the given source map into the given output object using the given TypeResolver and mapstructure.
func UnmarshalJSON ¶
func UnmarshalJSON(resolver TypeResolver, data []byte, output any) error
UnmarshalJSON unmarshals the given JSON data into the given output object using the given TypeResolver.
Types ¶
type Polymorphism ¶
type Polymorphism struct {
// contains filtered or unexported fields
}
type PolymorphismBuilderBase ¶
type PolymorphismBuilderBase struct {
// contains filtered or unexported fields
}
func (*PolymorphismBuilderBase) DefineTypeAt ¶
func (b *PolymorphismBuilderBase) DefineTypeAt(targetPath string) PolymorphismBuilderStrategySelector
func (*PolymorphismBuilderBase) UsingRule ¶
func (b *PolymorphismBuilderBase) UsingRule(rule Rule) PolymorphismBuilderRuleAdder
func (*PolymorphismBuilderBase) UsingTypeMap ¶
func (b *PolymorphismBuilderBase) UsingTypeMap(typeMap TypeMap) PolymorphismBuilderDiscriminatorKeyDefiner
type PolymorphismBuilderDiscriminatorKeyDefiner ¶
type PolymorphismBuilderDiscriminatorKeyDefiner interface {
WithDiscriminatorAt(discriminatorKey string) PolymorphismBuilderFinalizer
}
type PolymorphismBuilderEmpty ¶
type PolymorphismBuilderEmpty interface {
DefineTypeAt(targetPath string) PolymorphismBuilderStrategySelector
}
func NewPolymorphismBuilder ¶
func NewPolymorphismBuilder() PolymorphismBuilderEmpty
type PolymorphismBuilderFinalizer ¶
type PolymorphismBuilderFinalizer interface {
Build() (error, TypeResolver)
}
type PolymorphismBuilderRuleAdder ¶
type PolymorphismBuilderRuleAdder interface {
UsingRule(rule Rule) PolymorphismBuilderRuleAdder
Build() (error, TypeResolver)
}
type PolymorphismBuilderStrategySelector ¶
type PolymorphismBuilderStrategySelector interface {
UsingRule(rule Rule) PolymorphismBuilderRuleAdder
UsingTypeMap(typeMap TypeMap) PolymorphismBuilderDiscriminatorKeyDefiner
}
type PolymorphismRuleBuilder ¶
type PolymorphismRuleBuilder struct {
PolymorphismBuilderBase
// contains filtered or unexported fields
}
func (*PolymorphismRuleBuilder) Build ¶
func (b *PolymorphismRuleBuilder) Build() (error, TypeResolver)
func (*PolymorphismRuleBuilder) UsingRule ¶
func (b *PolymorphismRuleBuilder) UsingRule(rule Rule) PolymorphismBuilderRuleAdder
type PolymorphismTypeMapBuilder ¶
type PolymorphismTypeMapBuilder struct {
PolymorphismBuilderBase
// contains filtered or unexported fields
}
func (*PolymorphismTypeMapBuilder) Build ¶
func (b *PolymorphismTypeMapBuilder) Build() (error, TypeResolver)
func (*PolymorphismTypeMapBuilder) WithDiscriminatorAt ¶
func (b *PolymorphismTypeMapBuilder) WithDiscriminatorAt(discriminatorKey string) PolymorphismBuilderFinalizer
type Rule ¶
type Rule struct {
// ValuePath is the path to the value in the source to compare.
ValuePath objectpath.ObjectPath
// ComparatorFunction is the function to use to compare the value at ValuePath to.
ComparatorFunction func(any) bool
// NewType is the type to assign to the target if the rule matches.
NewType reflect.Type
}
Rule is a rule for a polymorphism mapper.
type RuleBuilder ¶
type RuleBuilder struct {
// contains filtered or unexported fields
}
RuleBuilder is a builder for a polymorphism rule.
func (*RuleBuilder) Build ¶
func (b *RuleBuilder) Build() ([]error, Rule)
Build builds the Rule and returns the errors encountered while building.
func (*RuleBuilder) IsEqualTo ¶
func (b *RuleBuilder) IsEqualTo(value any) RuleBuilderTypeAssigner
IsEqualTo sets the value to compare to.
func (*RuleBuilder) Matches ¶
func (b *RuleBuilder) Matches(comparator func(any) bool) RuleBuilderTypeAssigner
Matches sets the function to use to compare the value at ValuePath to.
func (*RuleBuilder) ThenAssignType ¶
func (b *RuleBuilder) ThenAssignType(newType reflect.Type) RuleBuilderFinalizer
ThenAssignType sets the type to assign to the target if the rule matches.
func (*RuleBuilder) WhenValueAt ¶
func (b *RuleBuilder) WhenValueAt(valuePath objectpath.ObjectPath) RuleBuilderConditionSetter
WhenValueAt sets the path to the value in the source to compare.
func (*RuleBuilder) WhenValueAtPathString ¶
func (b *RuleBuilder) WhenValueAtPathString(valuePath string) RuleBuilderConditionSetter
WhenValueAtPathString sets the path to the value in the source to compare.
type RuleBuilderBase ¶
type RuleBuilderBase interface {
WhenValueAt(valuePath objectpath.ObjectPath) RuleBuilderConditionSetter
WhenValueAtPathString(valuePath string) RuleBuilderConditionSetter
}
func NewRuleBuilder ¶
func NewRuleBuilder() RuleBuilderBase
NewRuleBuilder creates a new RuleBuilder. It enables a fluent interface for building a Rule.
type RuleBuilderConditionSetter ¶
type RuleBuilderConditionSetter interface {
IsEqualTo(value any) RuleBuilderTypeAssigner
Matches(comparator func(any) bool) RuleBuilderTypeAssigner
}
type RuleBuilderFinalizer ¶
type RuleBuilderTypeAssigner ¶
type RuleBuilderTypeAssigner interface {
ThenAssignType(newType reflect.Type) RuleBuilderFinalizer
}
type RulePolymorphism ¶
type RulePolymorphism struct {
Polymorphism
// contains filtered or unexported fields
}
RulePolymorphism is a mapper that assigns a target type based on the given rules
func (*RulePolymorphism) AssignTargetType ¶
func (p *RulePolymorphism) AssignTargetType(source any, target any) error
type TypeMapPolymorphism ¶
type TypeMapPolymorphism struct {
Polymorphism
// contains filtered or unexported fields
}
TypeMapPolymorphism is a mapper that assigns a target type based on a discriminator value and a type map
func (*TypeMapPolymorphism) AssignTargetType ¶
func (p *TypeMapPolymorphism) AssignTargetType(source any, target any) error
type TypeResolver ¶
type TypeResolver interface {
// AssignTargetType assigns the determined type to target based on the polymorphism rules. The matching rule with the
// highest priority is used. If no rule matches, the target type is not changed. The source and target must be pointers.
// If no matching type can be determined, an error.UnresolvedTypeError is returned.
AssignTargetType(source any, target any) error
}