Documentation
¶
Index ¶
- type BaseGenerator
- func (bg *BaseGenerator) AddImportsToFile(imp []parser.NamedTypeValue, src string) (string, error)
- func (bg *BaseGenerator) EnsureThatWeUseQualifierIfNeeded(tp string, imp []parser.NamedTypeValue) string
- func (bg *BaseGenerator) FindInterface(interfaceName string) (*parser.Interface, error)
- func (bg *BaseGenerator) GenerateNameBySample(sample string, exclude []parser.NamedTypeValue) string
- func (bg *BaseGenerator) Save(dir, filename string, args ...bool) error
- type CodeGenerator
- func (cg *CodeGenerator) AppendFunction(name string, receiver *jen.Statement, parameters []jen.Code, ...)
- func (cg *CodeGenerator) AppendInterface(name string, methods []jen.Code)
- func (cg *CodeGenerator) AppendMultilineComment(c []string)
- func (cg *CodeGenerator) AppendStruct(name string, fields ...jen.Code)
- func (cg *CodeGenerator) NewLine()
- func (cg *CodeGenerator) Raw() *jen.Statement
- func (cg *CodeGenerator) String() string
- type Generator
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type BaseGenerator ¶
type BaseGenerator struct { File *jen.File // empty go file CodeGenerator *CodeGenerator ParsedFile *parser.File // go file -> parsed file Buffer *bytes.Buffer // file content }
func Parse ¶
func Parse(dir, filename string, args ...string) (*BaseGenerator, error)
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 toa file that we edit with the generator
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) FindInterface ¶
func (bg *BaseGenerator) FindInterface(interfaceName string) (*parser.Interface, 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.
type CodeGenerator ¶
type CodeGenerator struct {
// contains filtered or unexported fields
}
CodeGenerator wraps a jen statement
func NewCodeGenerator ¶
func NewCodeGenerator(st *jen.Statement) *CodeGenerator
NewCodeGenerator returns a partial generator
func (*CodeGenerator) AppendFunction ¶
func (cg *CodeGenerator) 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 (*CodeGenerator) AppendInterface ¶
func (cg *CodeGenerator) AppendInterface(name string, methods []jen.Code)
func (*CodeGenerator) AppendMultilineComment ¶
func (cg *CodeGenerator) AppendMultilineComment(c []string)
func (*CodeGenerator) AppendStruct ¶
func (cg *CodeGenerator) AppendStruct(name string, fields ...jen.Code)
func (*CodeGenerator) NewLine ¶
func (cg *CodeGenerator) NewLine()
NewLine insert a new line in code.
func (*CodeGenerator) Raw ¶
func (cg *CodeGenerator) Raw() *jen.Statement
Raw returns the jen statement.
func (*CodeGenerator) String ¶
func (cg *CodeGenerator) String() string
String returns the source code string