Version: v0.0.0-...-075f0a8 Latest Latest

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

Go to latest
Published: Dec 15, 2021 License: MPL-2.0 Imports: 14 Imported by: 0




This section is empty.


This section is empty.


This section is empty.


type BaseGenerator

type BaseGenerator struct {
	Dir      string // the directory save the output file
	Filename string // Filename for output file

	JenFile    *jen.File    // original go file
	ParsedFile *parser.File // go file -> parsed file

	Builder *CodeBuilder

	GenFuncs []func() // sub generate functions
	// contains filtered or unexported fields

func NewBaseGenerator

func NewBaseGenerator(dir, filename string, overwrite bool, args ...string) (*BaseGenerator, error)

NewBaseGenerator parse file if file doesn't exist, read FileContent from the file the first variadic is package name if specified

func (*BaseGenerator) AddImportsToFile

func (bg *BaseGenerator) AddImportsToFile(imp []parser.NamedTypeValue, src string) (string, error)

AddImportsToFile adds missing imports to a file that we edit with the generator

func (*BaseGenerator) Deference

func (bg *BaseGenerator) Deference(v string) string

func (*BaseGenerator) EnsureThatWeUseQualifierIfNeeded

func (bg *BaseGenerator) EnsureThatWeUseQualifierIfNeeded(tp string, imp []parser.NamedTypeValue) string

EnsureThatWeUseQualifierIfNeeded is used to see if we need to import a path of a given type.

func (*BaseGenerator) FindConst

func (bg *BaseGenerator) FindConst(constName string) (*parser.NamedTypeValue, error)

func (*BaseGenerator) FindFuncType

func (bg *BaseGenerator) FindFuncType(funcType string) (*parser.FuncType, error)

func (*BaseGenerator) FindInterface

func (bg *BaseGenerator) FindInterface(interfaceName string) (*parser.Interface, error)

func (*BaseGenerator) FindMethod

func (bg *BaseGenerator) FindMethod(methodName string) (*parser.Method, error)

func (*BaseGenerator) FindStructure

func (bg *BaseGenerator) FindStructure(structureName string) (*parser.Struct, error)

func (*BaseGenerator) FindVar

func (bg *BaseGenerator) FindVar(varName string) (*parser.NamedTypeValue, error)

func (*BaseGenerator) Generate

func (bg *BaseGenerator) Generate(concrete Generator) error

func (*BaseGenerator) GenerateNameBySample

func (bg *BaseGenerator) GenerateNameBySample(sample string, exclude []parser.NamedTypeValue) string

GenerateNameBySample is used to generate a variable name using a sample.

The exclude parameter represents the names that it can not use.

E.x sample = "hello" this will return the name "h" if it is not in any NamedTypeValue name.

func (*BaseGenerator) GuessType

func (bg *BaseGenerator) GuessType(rawType string) string

GuessType guess what's the valid parameter type in method only process following cases: - `map[]Xxx or map[]*Xxx` - `[]Xxx or []*Xxx` - `Xxx or *Xxx` Above upper cased struct/interface will regards as comes from service package

func (*BaseGenerator) PostGenerate

func (bg *BaseGenerator) PostGenerate() error

func (*BaseGenerator) PreGenerate

func (bg *BaseGenerator) PreGenerate() error

func (*BaseGenerator) TypeAssert

func (bg *BaseGenerator) TypeAssert(to, source, tgtImportPath, target, errMsg string) []jen.Code

TypeAssert try to type assert to, ok = source.(target)

if !ok {
   return errors.New(errMsg)

type CodeBuilder

type CodeBuilder struct {
	// contains filtered or unexported fields

CodeBuilder wraps a jen statement

func NewCodeBuilder

func NewCodeBuilder(st *jen.Statement) *CodeBuilder

NewCodeBuilder returns a partial generator

func (*CodeBuilder) AppendFunction

func (cg *CodeBuilder) AppendFunction(name string, receiver *jen.Statement,
	parameters []jen.Code, results []jen.Code, oneResponse string, body ...jen.Code)

AppendFunction new a function name is the function name receiver is (* T), if no receiver, use nil parameters is function parameters inside func() if specified oneResponse, then function return type is `oneResponse` if oneResponse is empty, it will use results to set function return stuff

func (*CodeBuilder) AppendInterface

func (cg *CodeBuilder) AppendInterface(name string, methods []jen.Code)

func (*CodeBuilder) AppendMultilineComment

func (cg *CodeBuilder) AppendMultilineComment(c []string)

func (*CodeBuilder) AppendStruct

func (cg *CodeBuilder) AppendStruct(name string, fields ...jen.Code)

func (*CodeBuilder) NewLine

func (cg *CodeBuilder) NewLine()

NewLine insert a new line in code.

func (*CodeBuilder) Raw

func (cg *CodeBuilder) Raw() *jen.Statement

Raw returns the jen statement.

func (*CodeBuilder) String

func (cg *CodeBuilder) String() string

String returns the source code string

type Generator

type Generator interface {
	PreGenerate() error                // pre actions for generator
	Generate(concrete Generator) error // main generate function
	PostGenerate() error               // post actions
	GetGenCodeFuncs() []func()         // get gen code functions

Generator represents a generator.

type Meta

type Meta struct {
	RawSvcName             string            // service defined in .proto file
	SvcStructName          string            // service struct
	SvcServerInterfaceName string            // service interface name
	SvcServerInterface     *parser.Interface // service server interface found in .pb.go files
	RootDir                string
	ImportPaths            map[g.ImportType]string

func NewMeta

func NewMeta(rootDir string) (*Meta, error)

Jump to

Keyboard shortcuts

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