Documentation
¶
Index ¶
Constants ¶
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") )
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 ¶
var DstVarStyleValues = []DstVarStyle{DstVarReturn, DstVarArg}
DstVarStyleValues is a slice of all possible destination variable styles.
var MatchRuleValues = []MatchRule{MatchRuleName, MatchRuleTag, MatchRuleNone}
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 ¶
NewMatchRuleFromValue creates a new MatchRule instance from the given value string.
type NestStruct ¶
type NestStruct struct { InitExpr string NullCheckExpr string Contents []Assignment }
NestStruct represents a struct in a struct.
func (NestStruct) RetError ¶
func (s NestStruct) RetError() bool
RetError returns whether the assignment returns an error value.
func (NestStruct) String ¶
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 ¶
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.
type SliceAssignment ¶
SliceAssignment represents a slice assignment.
func (SliceAssignment) RetError ¶
func (c SliceAssignment) RetError() bool
RetError returns whether the assignment returns an error value.
func (SliceAssignment) String ¶
func (c SliceAssignment) String() string
String returns the string representation of the slice assignment.
type SliceLoopAssignment ¶
SliceLoopAssignment represents a slice assignment with a loop.
func (SliceLoopAssignment) RetError ¶
func (c SliceLoopAssignment) RetError() bool
RetError returns whether the assignment returns an error value.
func (SliceLoopAssignment) String ¶
func (c SliceLoopAssignment) String() string
String returns the string representation of the slice assignment with a loop.
type SliceTypecastAssignment ¶
SliceTypecastAssignment represents a slice assignment with a typecast.
func (SliceTypecastAssignment) RetError ¶
func (c SliceTypecastAssignment) RetError() bool
RetError returns whether the assignment returns an error value.
func (SliceTypecastAssignment) String ¶
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 ¶
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 ¶
PtrLessFullType creates a complete type expression string but omits the pointer "*" symbol at the top.