resolver

package
v0.20.0 Latest Latest
Warning

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

Go to latest
Published: Oct 16, 2023 License: MIT Imports: 7 Imported by: 1

Documentation

Overview

Package resolver contains the default implementation of github.com/rrgmc/instruct.Resolver.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type DefaultValueResolver

type DefaultValueResolver struct {
	CustomTypes        []TypeValueResolver
	CustomTypesReflect []TypeValueResolverReflect
}

func NewDefaultValueResolver

func NewDefaultValueResolver(options ...ValueOption) *DefaultValueResolver

func (DefaultValueResolver) ResolveValue

func (r DefaultValueResolver) ResolveValue(target reflect.Value, value any) error

type Option

type Option func(resolver *Resolver)

func WithValueResolver

func WithValueResolver(valueResolver ValueResolver) Option

WithValueResolver sets a custom ValueResolver to be used instead of the default.

type Resolver

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

Resolver is the default Resolver.

func NewResolver

func NewResolver(options ...Option) *Resolver

NewResolver creates a new default Resolver. If not ValueResolver was set, a default one that suports only primitive types is used.

func (Resolver) Resolve

func (r Resolver) Resolve(target reflect.Value, value any) error

type TypeValueResolver

type TypeValueResolver interface {
	ResolveTypeValue(target reflect.Value, value any) error
}

TypeValueResolver is a custom type handler for a ValueResolver. It should NOT process value using reflection (for performance reasons).

type TypeValueResolverReflect

type TypeValueResolverReflect interface {
	ResolveTypeValueReflect(target reflect.Value, sourceValue reflect.Value, value any) error
}

TypeValueResolverReflect is a custom type handler for a ValueResolver. It SHOULD process value using reflection.

type ValueOption

type ValueOption func(resolver *DefaultValueResolver)

func WithCustomType

func WithCustomType(customType TypeValueResolver) ValueOption

WithCustomType adds a custom type.

func WithCustomTypeReflect

func WithCustomTypeReflect(customType TypeValueResolverReflect) ValueOption

WithCustomTypeReflect adds a custom type that uses reflection.

func WithCustomTypes

func WithCustomTypes(customTypes ...TypeValueResolver) ValueOption

WithCustomTypes adds custom types.

func WithCustomTypesReflect

func WithCustomTypesReflect(customTypes ...TypeValueResolverReflect) ValueOption

WithCustomTypesReflect adds custom types that uses reflection.

type ValueResolver

type ValueResolver interface {
	// ResolveValue resolve the value to the proper type and return the value.
	ResolveValue(target reflect.Value, value any) error
}

ValueResolver resolves simple types for a Resolver. It should NOT handle slices, pointers, or maps.

type ValueResolverReflectTextUnmarshaler

type ValueResolverReflectTextUnmarshaler struct {
}

ValueResolverReflectTextUnmarshaler checks if target implements encoding.TextUnmarshaler and use it to resolve from string.

func NewValueResolverReflectTextUnmarshaler

func NewValueResolverReflectTextUnmarshaler() *ValueResolverReflectTextUnmarshaler

func (*ValueResolverReflectTextUnmarshaler) ResolveTypeValueReflect

func (d *ValueResolverReflectTextUnmarshaler) ResolveTypeValueReflect(target reflect.Value,
	sourceValue reflect.Value, value any) error

type ValueResolverTime

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

ValueResolverTime resolves time.Time values.

func NewValueResolverTime

func NewValueResolverTime(layout string) *ValueResolverTime

func (*ValueResolverTime) ResolveTypeValue

func (d *ValueResolverTime) ResolveTypeValue(target reflect.Value, value any) error

type ValueResolverTimeDuration

type ValueResolverTimeDuration struct {
}

ValueResolverTimeDuration resolves time.Duration values.

func NewValueResolverTimeDuration

func NewValueResolverTimeDuration() *ValueResolverTimeDuration

func (*ValueResolverTimeDuration) ResolveTypeValue

func (d *ValueResolverTimeDuration) ResolveTypeValue(target reflect.Value, value any) error

Jump to

Keyboard shortcuts

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