builder

package
v1.0.8 Latest Latest
Warning

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

Go to latest
Published: Nov 9, 2022 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ToString

func ToString(err *Error) string

ToString converts the error into a string.

Types

type Basic

type Basic struct{}

Basic handles basic data types.

func (*Basic) Build

func (*Basic) Build(_ Generator, _ *MethodContext, sourceID *xtype.JenID, source, target *xtype.Type) ([]jen.Code, *xtype.JenID, *Error)

Build creates conversion source code for the given source and target type.

func (*Basic) Matches

func (*Basic) Matches(source, target *xtype.Type, _ xtype.MethodKind) bool

Matches returns true, if the builder can create handle the given types.

type BasicTargetPointerRule

type BasicTargetPointerRule struct{}

BasicTargetPointerRule handles edge conditions if the target type is a pointer.

func (*BasicTargetPointerRule) Build

func (*BasicTargetPointerRule) Build(gen Generator, ctx *MethodContext, sourceID *xtype.JenID, source, target *xtype.Type) ([]jen.Code, *xtype.JenID, *Error)

Build creates conversion source code for the given source and target type.

func (*BasicTargetPointerRule) Matches

func (*BasicTargetPointerRule) Matches(source, target *xtype.Type, _ xtype.MethodKind) bool

Matches returns true, if the builder can create handle the given types.

type Builder

type Builder interface {
	// Matches returns true, if the builder can create handle the given types
	Matches(source, target *xtype.Type, kind xtype.MethodKind) bool
	// Build creates conversion source code for the given source and target type.
	Build(gen Generator, ctx *MethodContext, sourceID *xtype.JenID, source, target *xtype.Type) ([]jen.Code, *xtype.JenID, *Error)
}

Builder builds converter implementations, and can decide if it can handle the given type.

type Error

type Error struct {
	Path  []*Path
	Cause string
}

Error defines a conversion error.

func NewError

func NewError(cause string) *Error

NewError creates an error.

func (*Error) Lift

func (e *Error) Lift(paths ...*Path) *Error

Lift appends the path to the error.

type Generator

type Generator interface {
	Build(ctx *MethodContext, sourceID *xtype.JenID, source, target *xtype.Type) ([]jen.Code, *xtype.JenID, *Error)
	BuildWithExtend(ctx *MethodContext, sourceID *xtype.JenID, source, target *xtype.Type) (
		ok bool,
		codes []jen.Code,
		id *xtype.JenID,
		err *Error,
	)
	Name() string
}

Generator checks all existing builders if they can create a conversion implementations for the given source and target type If no one Builder#Matches then, an error is returned.

type List

type List struct{}

List handles array / slice types.

func (*List) Build

func (*List) Build(gen Generator, ctx *MethodContext, sourceID *xtype.JenID, source, target *xtype.Type) ([]jen.Code, *xtype.JenID, *Error)

Build creates conversion source code for the given source and target type.

func (*List) Matches

func (*List) Matches(source, target *xtype.Type, kind xtype.MethodKind) bool

Matches returns true, if the builder can create handle the given types.

type Map

type Map struct{}

Map handles map types.

func (*Map) Build

func (*Map) Build(gen Generator, ctx *MethodContext, sourceID *xtype.JenID, source, target *xtype.Type) ([]jen.Code, *xtype.JenID, *Error)

Build creates conversion source code for the given source and target type.

func (*Map) Matches

func (*Map) Matches(source, target *xtype.Type, kind xtype.MethodKind) bool

Matches returns true, if the builder can create handle the given types.

type MethodContext

type MethodContext struct {
	*namer.Namer
	Mapping          map[string]string
	IgnoredFields    map[string]struct{}
	IdentityMapping  map[string]struct{}
	GlobalExtend     map[xtype.Signature]*MethodDefinition
	MethodExtend     map[xtype.Signature]*MethodDefinition
	SearchTag        []string
	Signature        xtype.Signature
	TargetType       *xtype.Type
	WantMethodKind   xtype.MethodKind
	MatchIgnoreCase  bool
	NoStrict         bool
	IgnoreUnexported bool
	TargetID         *xtype.JenID
	ID               string
}

MethodContext exposes information for the current method.

func (*MethodContext) Enter

func (m *MethodContext) Enter() *MethodContext

func (*MethodContext) EnterWithNamer added in v1.0.2

func (m *MethodContext) EnterWithNamer() *MethodContext

type MethodDefinition

type MethodDefinition struct {
	ID       string
	Explicit bool
	Name     string
	Call     *jen.Statement
	Source   *xtype.Type
	Target   *xtype.Type
	Kind     xtype.MethodKind

	Jen jen.Code

	SelfAsFirstParam bool
	ReturnError      bool
	ReturnTypeOrigin string
	Dirty            bool
}

type Path

type Path struct {
	Prefix     string
	SourceID   string
	TargetID   string
	SourceType string
	TargetType string
}

Path defines the path inside an error message.

type Pointer

type Pointer struct{}

Pointer handles pointer types.

func (*Pointer) Build

func (*Pointer) Build(gen Generator, ctx *MethodContext, sourceID *xtype.JenID, source, target *xtype.Type) ([]jen.Code, *xtype.JenID, *Error)

Build creates conversion source code for the given source and target type.

func (*Pointer) Matches

func (*Pointer) Matches(source, target *xtype.Type, kind xtype.MethodKind) bool

Matches returns true, if the builder can create handle the given types.

type Struct

type Struct struct{}

Struct handles struct types.

func (*Struct) Build

func (*Struct) Build(gen Generator, ctx *MethodContext, sourceID *xtype.JenID, source, target *xtype.Type) ([]jen.Code, *xtype.JenID, *Error)

Build creates conversion source code for the given source and target type.

func (*Struct) Matches

func (p *Struct) Matches(source, target *xtype.Type, _ xtype.MethodKind) bool

Matches returns true, if the builder can create handle the given types.

type TargetPointer

type TargetPointer struct{}

TargetPointer handles type were only the target is a pointer.

func (*TargetPointer) Build

func (*TargetPointer) Build(gen Generator, ctx *MethodContext, sourceID *xtype.JenID, source, target *xtype.Type) ([]jen.Code, *xtype.JenID, *Error)

Build creates conversion source code for the given source and target type.

func (*TargetPointer) Matches

func (*TargetPointer) Matches(source, target *xtype.Type, kind xtype.MethodKind) bool

Matches returns true, if the builder can create handle the given types.

type TargetStruct

type TargetStruct struct{}

func (*TargetStruct) Build

func (t *TargetStruct) Build(gen Generator, ctx *MethodContext, sourceID *xtype.JenID, source, target *xtype.Type) ([]jen.Code, *xtype.JenID, *Error)

func (*TargetStruct) Matches

func (t *TargetStruct) Matches(source, target *xtype.Type, kind xtype.MethodKind) bool

type ZeroCopyStruct

type ZeroCopyStruct struct{}

func (*ZeroCopyStruct) Build

func (z *ZeroCopyStruct) Build(gen Generator, ctx *MethodContext, sourceID *xtype.JenID, source, target *xtype.Type) ([]jen.Code, *xtype.JenID, *Error)

func (*ZeroCopyStruct) Matches

func (z *ZeroCopyStruct) Matches(source, target *xtype.Type, kind xtype.MethodKind) bool

Jump to

Keyboard shortcuts

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