option

package
v0.7.2 Latest Latest
Warning

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

Go to latest
Published: Oct 30, 2024 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ValidOpsIntf = map[string]struct{}{
	"convergen":    {},
	"style":        {},
	"match":        {},
	"case":         {},
	"case:off":     {},
	"getter":       {},
	"getter:off":   {},
	"stringer":     {},
	"stringer:off": {},
	"typecast":     {},
	"typecast:off": {},
}

ValidOpsIntf is a set of valid conversion option keys for interface-level conversion.

View Source
var ValidOpsMethod = map[string]struct{}{
	"style":        {},
	"match":        {},
	"case":         {},
	"case:off":     {},
	"getter":       {},
	"getter:off":   {},
	"stringer":     {},
	"stringer:off": {},
	"typecast":     {},
	"typecast:off": {},
	"recv":         {},
	"reverse":      {},
	"skip":         {},
	"map":          {},
	"tag":          {},
	"conv":         {},
	"conv:type":    {},
	"conv:with":    {},
	"literal":      {},
	"preprocess":   {},
	"postprocess":  {},
}

ValidOpsMethod is a set of valid conversion option keys for method-level conversion.

Functions

This section is empty.

Types

type FieldConverter

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

FieldConverter represents a converter for a single field of the source and destination types.

func NewFieldConverter

func NewFieldConverter(converter, src, dst string, pos token.Pos) *FieldConverter

NewFieldConverter creates a new FieldConverter with the given parameters.

func (*FieldConverter) ArgType

func (c *FieldConverter) ArgType() types.Type

ArgType returns the type of the converter's argument.

func (*FieldConverter) Converter

func (c *FieldConverter) Converter() string

Converter returns the name of the converter function.

func (*FieldConverter) Dst

func (c *FieldConverter) Dst() *IdentMatcher

Dst returns the FieldConverter's destination identifier matcher.

func (*FieldConverter) Match

func (c *FieldConverter) Match(src, dst string) bool

Match returns true if the given source and destination field names match the FieldConverter's name matcher.

func (*FieldConverter) Pos

func (c *FieldConverter) Pos() token.Pos

Pos returns the position of the FieldConverter.

func (*FieldConverter) RHSExpr

func (c *FieldConverter) RHSExpr(arg string) string

RHSExpr returns the right-hand side expression of the FieldConverter for a given argument.

func (*FieldConverter) RetError

func (c *FieldConverter) RetError() bool

RetError returns true if the converter returns an error.

func (*FieldConverter) RetType

func (c *FieldConverter) RetType() types.Type

RetType returns the type of the converter's return value.

func (*FieldConverter) Set

func (c *FieldConverter) Set(argType, retType types.Type, returnError bool)

Set sets the types of the FieldConverter's argument and return value, as well as whether the converter returns an error.

func (*FieldConverter) Src

func (c *FieldConverter) Src() *IdentMatcher

Src returns the FieldConverter's source identifier matcher.

type IdentMatcher

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

IdentMatcher is used to match field or method names in a struct.

func NewIdentMatcher

func NewIdentMatcher(pattern string) *IdentMatcher

NewIdentMatcher creates a new IdentMatcher instance with a given pattern.

func (*IdentMatcher) ExprAt

func (m *IdentMatcher) ExprAt(at int) string

ExprAt returns an expression at the path index. If it is of a method, it should contain parens like "GetValue()".

func (*IdentMatcher) ForGetter

func (m *IdentMatcher) ForGetter(at int) bool

ForGetter returns true if the path at the given index represents a method that returns a value.

func (*IdentMatcher) Match

func (m *IdentMatcher) Match(ident string, exactCase bool) bool

Match returns true if the given ident string matches the IdentMatcher's pattern. If exactCase is false, it matches case-insensitively.

func (*IdentMatcher) NameAt

func (m *IdentMatcher) NameAt(at int) string

NameAt returns the name of the field or method at the path index. If it is a method, it removes the parentheses.

func (*IdentMatcher) PartialMatch

func (m *IdentMatcher) PartialMatch(ident string, exactCase bool) bool

PartialMatch returns true if the given ident string partially matches the IdentMatcher's pattern. If exactCase is false, it matches case-insensitively.

func (*IdentMatcher) PathLen

func (m *IdentMatcher) PathLen() int

PathLen returns the length of the path.

func (*IdentMatcher) String

func (m *IdentMatcher) String() string

type LiteralSetter

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

LiteralSetter sets the literal value to the destination identified by dst.

func NewLiteralSetter

func NewLiteralSetter(dst, literal string, pos token.Pos) *LiteralSetter

NewLiteralSetter creates a new LiteralSetter instance.

func (*LiteralSetter) Dst

func (m *LiteralSetter) Dst() *IdentMatcher

Dst returns the IdentMatcher instance for the destination.

func (*LiteralSetter) Literal

func (m *LiteralSetter) Literal() string

Literal returns the literal value.

func (*LiteralSetter) Match

func (m *LiteralSetter) Match(dst string, exactCase bool) bool

Match checks whether the destination matches the pattern of the IdentMatcher.

func (*LiteralSetter) Pos

func (m *LiteralSetter) Pos() token.Pos

Pos returns the position of the setter in the source code.

type Manipulator

type Manipulator struct {
	Func     types.Object // Func represents the function object that this manipulator invokes.
	DstSide  types.Type   // DstSide is the type expression of the destination side.
	SrcSide  types.Type   // SrcSide is the type expression of the source side.
	RetError bool         // RetError indicates whether the manipulator returns an error or not.
	Pos      token.Pos    // Pos represents the position of the manipulator in the source code.
}

Manipulator represents a manipulator that manipulates the source and destination types.

type NameMatcher

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

NameMatcher matches source and destination names.

func NewNameMatcher

func NewNameMatcher(src, dst string, pos token.Pos) *NameMatcher

NewNameMatcher creates a new NameMatcher instance.

func (*NameMatcher) Dst

func (m *NameMatcher) Dst() *IdentMatcher

Dst returns the destination IdentMatcher.

func (*NameMatcher) Match

func (m *NameMatcher) Match(src, dst string, exactCase bool) bool

Match matches source and destination with the given names.

func (*NameMatcher) Pos

func (m *NameMatcher) Pos() token.Pos

Pos returns the token.Pos of NameMatcher.

func (*NameMatcher) Src

func (m *NameMatcher) Src() *IdentMatcher

Src returns the source IdentMatcher.

type Options

type Options struct {
	Style       model.DstVarStyle // Style of the destination variable name
	Rule        model.MatchRule   // Matching rule for fields
	ExactCase   bool              // Whether to match fields with exact case sensitivity
	Getter      bool              // Whether to use getter methods to access fields
	Stringer    bool              // Whether to use stringer methods to convert values to strings
	Typecast    bool              // Whether to use explicit typecasts when converting values
	Receiver    string            // Receiver name for method generation
	Reverse     bool              // Whether to reverse the order of struct tags
	SkipFields  []*PatternMatcher // List of field names to skip during conversion
	NameMapper  []*NameMatcher    // List of field name mapping rules
	Converters  []*FieldConverter // List of field conversion rules
	Literals    []*LiteralSetter  // List of literal value setting rules
	PreProcess  *Manipulator      // Manipulator to run before struct processing
	PostProcess *Manipulator      // Manipulator to run after struct processing
}

Options represents the conversion options.

func NewOptions

func NewOptions() Options

NewOptions returns a new Options instance.

func (Options) CompareFieldName

func (o Options) CompareFieldName(a, b string) bool

CompareFieldName compares two field names.

func (Options) ShouldSkip

func (o Options) ShouldSkip(fieldName string) bool

ShouldSkip returns true if the field with the given name should be skipped.

type PatternMatcher

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

PatternMatcher matches a string against a pattern.

func NewPatternMatcher

func NewPatternMatcher(pattern string, exactCase bool) (*PatternMatcher, error)

NewPatternMatcher creates a new PatternMatcher instance.

func (*PatternMatcher) Match

func (m *PatternMatcher) Match(ident string, exactCase bool) bool

Match checks whether the input string matches the pattern.

Jump to

Keyboard shortcuts

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