Thanks to visit codestin.com
Credit goes to pkg.go.dev

codegen

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Jul 9, 2020 License: BSD-3-Clause Imports: 4 Imported by: 5

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FormatPackageDocumentation

func FormatPackageDocumentation(s string) string

FormatPackageDocumentation is used to format package-level comments.

func This

func This() string

This returns the string variable used by members to refer to themselves.

Types

type Function

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

Function represents a free function, not a method, for Go code to be generated.

func NewCommentedFunction

func NewCommentedFunction(pkg, name string,
	params, ret, block []jen.Code,
	comment string) *Function

NewCommentedFunction creates a new function with a comment.

func NewFunction

func NewFunction(pkg, name string,
	params, ret, block []jen.Code) *Function

NewFunction creates a new function without any comments.

func (Function) Call

func (m Function) Call(params ...jen.Code) jen.Code

Call generates the Go code required to call this function, with qualifier if required.

func (Function) CloneToPackage

func (m Function) CloneToPackage(pkg string) *Function

CloneToPackage copies this Function into a new one defined in the provided package

func (Function) Definition

func (m Function) Definition() jen.Code

Definition generates the Go code required to define and implement this function.

func (Function) Name

func (m Function) Name() string

Name returns the identifier of this function.

func (Function) QualifiedName

func (m Function) QualifiedName() *jen.Statement

QualifiedName returns the qualified identifier for this function.

func (Function) ToFunctionSignature

func (m Function) ToFunctionSignature() FunctionSignature

ToFunctionSignature obtains this function's FunctionSignature.

type FunctionSignature

type FunctionSignature struct {
	Name    string
	Params  []jen.Code
	Ret     []jen.Code
	Comment string
}

FunctionSignature is an interface's function definition without an implementation.

func (FunctionSignature) Signature

func (f FunctionSignature) Signature() jen.Code

Signature returns the uncommented raw signature.

type Interface

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

Interface manages and generates a Golang interface definition.

func NewInterface

func NewInterface(pkg, name string,
	funcs []FunctionSignature,
	comment string) *Interface

NewInterface creates an Interface.

func (Interface) Definition

func (i Interface) Definition() jen.Code

Definition produces the Golang code.

type Method

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

Method represents a method on a type, not a free function, for Go code to be generated.

func NewCommentedPointerMethod

func NewCommentedPointerMethod(pkg, name, structName string,
	params, ret, block []jen.Code,
	comment string) *Method

NewCommentedPointerMethod defines a commented method for the pointer to a type.

func NewCommentedValueMethod

func NewCommentedValueMethod(pkg, name, structName string,
	params, ret, block []jen.Code,
	comment string) *Method

NewCommentedValueMethod defines a commented method for the value of a type.

func NewPointerMethod

func NewPointerMethod(pkg, name, structName string,
	params, ret, block []jen.Code) *Method

NewPointerMethod defines a method for the pointer to a type. It is not commented.

func NewValueMethod

func NewValueMethod(pkg, name, structName string,
	params, ret, block []jen.Code) *Method

NewValueMethod defines a method for the value of a type. It is not commented.

func (Method) Call

func (m Method) Call(on string, params ...jen.Code) jen.Code

Call generates the Go code required to call this method, with qualifier if required.

func (Method) Definition

func (m Method) Definition() jen.Code

Definition generates the Go code required to define and implement this method.

func (Method) Name

func (m Method) Name() string

Name returns the identifier of this function.

func (Method) On

func (m Method) On(on string) *jen.Statement

On generates the Go code that determines the qualified method name on a specific variable.

func (Method) ToFunctionSignature

func (m Method) ToFunctionSignature() FunctionSignature

ToFunctionSignature obtains this method's FunctionSignature.

type Struct

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

Struct defines a struct-based type, its functions, and its methods for Go code generation.

func NewStruct

func NewStruct(comment string,
	name string,
	methods []*Method,
	constructors []*Function,
	members []jen.Code) *Struct

NewStruct creates a new commented Struct type.

func (*Struct) Constructors

func (s *Struct) Constructors(name string) *Function

Constructors obtains the Go code to be generated for the function with a specific name. Panics if no such function exists.

func (*Struct) Definition

func (s *Struct) Definition() jen.Code

Definition generates the Go code required to define and implement this struct, its methods, and its functions.

func (*Struct) Method

func (s *Struct) Method(name string) *Method

Method obtains the Go code to be generated for the method with a specific name. Panics if no such method exists.

func (*Struct) ToInterface

func (s *Struct) ToInterface(pkg, name, comment string) *Interface

ToInterface creates an interface version of this struct.

type Typedef

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

Typedef defines a non-struct-based type, its functions, and its methods for Go code generation.

func NewTypedef

func NewTypedef(comment string,
	name string,
	concreteType jen.Code,
	methods []*Method,
	constructors []*Function) *Typedef

NewTypedef creates a new commented Typedef.

func (*Typedef) Constructors

func (t *Typedef) Constructors(name string) *Function

Constructors obtains the Go code to be generated for the function with a specific name. Panics if no such function exists.

func (*Typedef) Definition

func (t *Typedef) Definition() jen.Code

Definition generates the Go code required to define and implement this type, its methods, and its functions.

func (*Typedef) Method

func (t *Typedef) Method(name string) *Method

Method obtains the Go code to be generated for the method with a specific name. Panics if no such method exists.

func (*Typedef) ToInterface

func (t *Typedef) ToInterface(pkg, name, comment string) *Interface

ToInterface creates an interface version of this typedef.

Jump to

Keyboard shortcuts

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