resolver

package
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 27, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package resolver determines field mappings between struct types.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Error

type Error struct {
	Field   string
	Message string
}

Error represents a resolution error.

func (Error) Error

func (e Error) Error() string

type Errors

type Errors []Error

Errors is a collection of resolution errors.

func (*Errors) Add

func (e *Errors) Add(field, message string)

Add adds an error to the collection.

func (Errors) Error

func (e Errors) Error() string

func (Errors) HasErrors

func (e Errors) HasErrors() bool

HasErrors returns true if there are any errors.

type FieldMapping

type FieldMapping struct {
	// SourceField is the source field name
	SourceField string
	// TargetField is the target field name
	TargetField string
	// SourceType is the source field type
	SourceType types.Type
	// TargetType is the target field type
	TargetType types.Type
	// Kind indicates the type of mapping
	Kind MappingKind
	// Converter is the converter to use (for KindConverter)
	Converter *registry.Converter
	// NestedMapper is the generated mapper function name (for KindNested)
	NestedMapper string
	// HasError indicates if this mapping may produce an error
	HasError bool
}

FieldMapping describes how to map a source field to a target field.

type Mapping

type Mapping struct {
	Source   *analyzer.StructInfo
	Target   *analyzer.StructInfo
	Fields   []FieldMapping
	HasError bool // true if any field mapping may produce an error
}

Mapping holds the complete mapping between two struct types.

type MappingKind

type MappingKind int

MappingKind indicates the type of field mapping.

const (
	// KindDirect is a direct copy (same name, same type).
	KindDirect MappingKind = iota
	// KindConverter uses a registered converter.
	KindConverter
	// KindNested uses a generated nested mapper.
	KindNested
	// KindSlice maps slice elements.
	KindSlice
	// KindIgnore ignores the field (map:"-" or target-only field).
	KindIgnore
)

type Resolver

type Resolver struct {
	// contains filtered or unexported fields
}

Resolver resolves field mappings between struct types.

func New

func New(reg *registry.Registry) *Resolver

New creates a new Resolver.

func (*Resolver) Resolve

func (r *Resolver) Resolve(source, target *analyzer.StructInfo) (*Mapping, Errors)

Resolve determines the field mappings from source to target.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL