Documentation ¶
Overview ¶
Copyright (c) 2023 thorstenrie. All Rights Reserved. Use is governed with GNU Affero General Public License v3.0 that can be found in the LICENSE file.
Does not check for correct syntax or arguments ¶
Copyright (c) 2023 thorstenrie. All Rights Reserved. Use is governed with GNU Affero General Public License v3.0 that can be found in the LICENSE file.
Index ¶
- type AssignmentArgs
- type Code
- func (code *Code) Addr() *Code
- func (code *Code) Assignment(a *AssignmentArgs) *Code
- func (code *Code) BlockEnd() *Code
- func (code *Code) Call(n string) *Code
- func (code *Code) CompositeLit(LiteralType string) *Code
- func (code *Code) Format() error
- func (code *Code) Func1(a *Func1Args) *Code
- func (code *Code) FuncEnd() *Code
- func (code *Code) Ident(n string) *Code
- func (code *Code) If(a *IfArgs) *Code
- func (code *Code) IfErr(a *IfErrArgs) *Code
- func (code *Code) KeyedElement(a *KeyedElementArgs) *Code
- func (code *Code) LineComment(c string) *Code
- func (code *Code) List() *Code
- func (code *Code) Listln() *Code
- func (code *Code) ParamEnd() *Code
- func (code *Code) ParamEndln() *Code
- func (code *Code) Return() *Code
- func (code *Code) SelField(a *SelArgs) *Code
- func (code *Code) SelMethod(a *SelArgs) *Code
- func (code *Code) ShortVarDecl(a *ShortVarDeclArgs) *Code
- func (code *Code) String() string
- func (code *Code) Testvariables(t *Testvars) *Code
- func (code *Code) TypeStruct(n string) *Code
- func (code *Code) VarSpec(a *VarSpecArgs) *Code
- type Codefile
- type Func1Args
- type IfArgs
- type IfErrArgs
- type KeyedElementArgs
- type SelArgs
- type ShortVarDeclArgs
- type Testvars
- type VarSpecArgs
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type AssignmentArgs ¶
type AssignmentArgs struct {
ExprLeft, ExprRight string
}
type Code ¶
type Code struct {
// contains filtered or unexported fields
}
Code contains the source code as string. The source code is amended by its methods. The source code can be retrieved with String and formatted with Format.
func NewCode ¶
func NewCode() *Code
NewCode returns a pointer to a new Code instance. The source code in the new Code instance is empty.
func (*Code) CompositeLit ¶
Composite Literal
func (*Code) Format ¶
Format formats the source code in code in canonical gfmt style. It uses Source from the go/format package. Format returns an error if code is nil or if go/format returns an error.
func (*Code) KeyedElement ¶
func (code *Code) KeyedElement(a *KeyedElementArgs) *Code
KeyedElement generates a keyed element of a composite literal: Key: Element,\n. The key and element is provided by a. It returns nil if a is nil.
func (*Code) LineComment ¶
LineComment adds a line comment and a new line to code: // c\n. The comment is provided by argument c.
func (*Code) ParamEndln ¶
ParamEndln adds a parameters ending and a new line to code: )\n.
func (*Code) SelField ¶
SelField adds a field selector to code: val.sel. The value val and selector sel are provided by a. It returns nil if a is nil.
func (*Code) SelMethod ¶
SelMethod adds a method selector to code: val.sel(. The value val and selector sel are provided by a. It returns nil if a is nil.
func (*Code) ShortVarDecl ¶
func (code *Code) ShortVarDecl(a *ShortVarDeclArgs) *Code
ShortVarDecl generates a short variable declaration: Ident := Expr\n. The identifier and expression is provided by a. It returns nil if a is nil.
func (*Code) String ¶
String returns the source code in code as string. It returns an empty string if code is nil.
func (*Code) Testvariables ¶
Testvariables generates test variables for unit tests. The test variables are generated based on t. A test variable is generated if the corresponding type in t is not equal to zero. It returns nil if t is nil.
func (*Code) TypeStruct ¶
TypeStruct adds a type declaration for a struct type to code: type n struct {\n. The name of the type is provided with n.
func (*Code) VarSpec ¶
func (code *Code) VarSpec(a *VarSpecArgs) *Code
VarSpec adds a variable specification to code: Ident Type\n. The identifier and type is provided by a.
type Codefile ¶
type Codefile struct {
// contains filtered or unexported fields
}
func (*Codefile) FinishFile ¶
type KeyedElementArgs ¶
type KeyedElementArgs struct {
Key, Elem string
}
KeyedElementArgs contains the key Key and element Elem to generate a keyed element of a composite literal with KeyedElement
type ShortVarDeclArgs ¶
type ShortVarDeclArgs struct {
Ident, Expr string
}
ShortVarDeclArgs contains the identifier Ident and expression Expr to generate a short variable declaration with ShortVarDecl
type Testvars ¶
type Testvars struct {
String, Error, Int, Float int
}
Testvars contains the configuration for the generation of test variables with Testvariables A test variable is generated if the corresponding type is not equal to zero.
type VarSpecArgs ¶
type VarSpecArgs struct {
Ident, Type string
}
VarSpecArgs contains the identifier Ident and type Type to generate a variable specification with VarSpec