model

package
v0.6.4 Latest Latest
Warning

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

Go to latest
Published: Mar 11, 2024 License: MIT Imports: 2 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// DstVarReturn indicates that the destination variable is a return
	// value in a function signature.
	DstVarReturn = DstVarStyle("return")
	// DstVarArg indicates that the destination variable is an argument
	// in a function signature.
	DstVarArg = DstVarStyle("arg")
)
View Source
const (
	// MatchRuleName indicates that the field name is used as the matching criteria.
	MatchRuleName = MatchRule("name")
	// MatchRuleTag indicates that the field tag is used as the matching criteria.
	MatchRuleTag = MatchRule("tag")
	// MatchRuleNone indicates that there is no matching criteria for the field.
	MatchRuleNone = MatchRule("none")
)

Variables

View Source
var DstVarStyleValues = []DstVarStyle{DstVarReturn, DstVarArg}

DstVarStyleValues is a slice of all possible destination variable styles.

MatchRuleValues is a slice of all possible field matching rules.

Functions

This section is empty.

Types

type Assignment

type Assignment interface {
	// String returns the string representation of the assignment.
	String() string
	// RetError returns whether the assignment returns an error value.
	RetError() bool
}

Assignment represents an assignment between fields in a struct.

type Code

type Code struct {
	// PackageName is the name of the package.
	BaseCode string
	// FunctionsBlock is the generated code for the functions.
	FunctionBlocks []FunctionsBlock
}

Code represents the generated code.

type DstVarStyle

type DstVarStyle string

DstVarStyle represents the style of destination variable in a function signature.

func NewDstVarStyleFromValue

func NewDstVarStyleFromValue(v string) (DstVarStyle, bool)

NewDstVarStyleFromValue creates a new DstVarStyle instance from the given value string.

func (DstVarStyle) String

func (s DstVarStyle) String() string

String returns the string representation of the destination variable style.

type Function

type Function struct {
	Comments    []string     // Comments is the list of comment lines before the function definition.
	Name        string       // Name is the function name.
	Receiver    string       // Receiver is the receiver type name, if any.
	Src         Var          // Src is the source variable.
	Dst         Var          // Dst is the destination variable.
	RetError    bool         // RetError indicates whether the function returns an error.
	DstVarStyle DstVarStyle  // DstVarStyle is the style of the destination variable declaration.
	Assignments []Assignment // Assignments is the list of assignments in the function body.
	PreProcess  *Manipulator // PreProcess is the function that is applied before the assignments.
	PostProcess *Manipulator // PostProcess is the function that is applied after the assignments.
}

Function represents a function.

type FunctionsBlock

type FunctionsBlock struct {
	Marker    string      // Marker is a special comment marker for indicating a specific section of functions.
	Functions []*Function // Functions is the list of functions.
}

FunctionsBlock represents a group of functions.

type Manipulator

type Manipulator struct {
	Pkg      string // Pkg is the package name of the function.
	Name     string // Name is the name of the function.
	IsDstPtr bool   // IsDstPtr indicates that the first argument is a pointer to the destination.
	IsSrcPtr bool   // IsSrcPtr indicates that the second argument is a pointer to the source.
	RetError bool   // RetError indicates that the function returns an error.
}

Manipulator represents a function that manipulates a value.

func (*Manipulator) FuncName

func (m *Manipulator) FuncName() string

FuncName returns the fully qualified name of the function.

type MatchRule

type MatchRule string

MatchRule represents the field matching rule.

func NewMatchRuleFromValue

func NewMatchRuleFromValue(v string) (MatchRule, bool)

NewMatchRuleFromValue creates a new MatchRule instance from the given value string.

func (MatchRule) String

func (s MatchRule) String() string

String returns the string representation of the match rule.

type NestStruct added in v0.5.0

type NestStruct struct {
	InitExpr      string
	NullCheckExpr string
	Contents      []Assignment
}

NestStruct represents a struct in a struct.

func (NestStruct) RetError added in v0.5.0

func (s NestStruct) RetError() bool

RetError returns whether the assignment returns an error value.

func (NestStruct) String added in v0.5.0

func (s NestStruct) String() string

String returns the string representation of the nested struct assignment.

type NoMatchField

type NoMatchField struct {
	LHS string // LHS is the name of the field that doesn't match any fields or getters.
}

NoMatchField indicates that the field is skipped while there was no matching fields or getters.

func (NoMatchField) RetError

func (s NoMatchField) RetError() bool

RetError always returns false for no match field assignments.

func (NoMatchField) String

func (s NoMatchField) String() string

String returns the string representation of the no match field assignment.

type SimpleField

type SimpleField struct {
	LHS   string
	RHS   string
	Error bool
}

SimpleField represents an RHS expression.

func (SimpleField) RetError

func (s SimpleField) RetError() bool

RetError returns whether the assignment returns an error value.

func (SimpleField) String

func (s SimpleField) String() string

String returns the string representation of the simple field assignment.

type SkipField

type SkipField struct {
	LHS string // LHS is the left-hand side of the skipped field.
}

SkipField indicates that the field is skipped due to a :skip notation.

func (SkipField) RetError

func (s SkipField) RetError() bool

RetError always returns false for skip field assignments.

func (SkipField) String

func (s SkipField) String() string

String returns the string representation of the skip field assignment.

type SliceAssignment added in v0.5.0

type SliceAssignment struct {
	LHS string
	RHS string
	Typ string
}

SliceAssignment represents a slice assignment.

func (SliceAssignment) RetError added in v0.5.0

func (c SliceAssignment) RetError() bool

RetError returns whether the assignment returns an error value.

func (SliceAssignment) String added in v0.5.0

func (c SliceAssignment) String() string

String returns the string representation of the slice assignment.

type SliceLoopAssignment added in v0.5.0

type SliceLoopAssignment struct {
	LHS string
	RHS string
	Typ string
}

SliceLoopAssignment represents a slice assignment with a loop.

func (SliceLoopAssignment) RetError added in v0.5.0

func (c SliceLoopAssignment) RetError() bool

RetError returns whether the assignment returns an error value.

func (SliceLoopAssignment) String added in v0.5.0

func (c SliceLoopAssignment) String() string

String returns the string representation of the slice assignment with a loop.

type SliceTypecastAssignment added in v0.5.0

type SliceTypecastAssignment struct {
	LHS  string
	RHS  string
	Typ  string
	Cast string
}

SliceTypecastAssignment represents a slice assignment with a typecast.

func (SliceTypecastAssignment) RetError added in v0.5.0

func (c SliceTypecastAssignment) RetError() bool

RetError returns whether the assignment returns an error value.

func (SliceTypecastAssignment) String added in v0.5.0

func (c SliceTypecastAssignment) String() string

String returns the string representation of the slice assignment with a typecast.

type Var

type Var struct {
	// Name is the name of the variable.
	Name string
	// Type represents the type expression of the variable without pointer mark "*".
	// If the type is of an external package, Type has its package name in the code, too. (e.g. model.User)
	Type string
	// Pointer indicates whether the variable is defined as a pointer.
	Pointer bool
	// External indicates whether the Type is defined in an external package.
	External bool
}

Var represents a defined variable.

func (Var) FullType

func (v Var) FullType() string

FullType creates a complete type expression string that can be used for var declaration. E.g. "*model.Pet" for "var x *model.Pet".

func (Var) PtrLessFullType

func (v Var) PtrLessFullType() string

PtrLessFullType creates a complete type expression string but omits the pointer "*" symbol at the top.

Jump to

Keyboard shortcuts

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