Documentation
¶
Index ¶
- Variables
- func AddDefaultPackageComment(f *jen.File, generatorName string, version string) *jen.File
- func FindFunction(f *types.File, name string) *types.Function
- func FindInterface(f *types.File, name string) *types.Interface
- func FindMethod(f *types.File, name string) *types.Method
- func FindStructure(f *types.File, name string) *types.Struct
- func IsChanType(t types.Type) bool
- func IsErrorType(t types.Type) bool
- func IsNillableType(t types.Type) bool
- func IsPointerType(t types.Type) bool
- func RegisterGobTypes()
- func RunTestCases(t *testing.T, testCases []TestCase, generator Generator, ...)
- func TypeQual(currentPackage string, targetPackage string, t types.Type) *jen.Statement
- func WithGoldenFileGeneration() testCaseOption
- type Client
- type GenerateParams
- type GenerateResult
- type GenerateResultFile
- type Generator
- type NetRPCWorker
- type PluginGenerateResult
- type Server
- type TestCase
Constants ¶
This section is empty.
Variables ¶
var DefaultHandshakeConfig = plugin.HandshakeConfig{
ProtocolVersion: 1,
MagicCookieKey: "HOST",
MagicCookieValue: "GEN",
}
DefaultHandshakeConfig useful for plugin compatibility specification.
Functions ¶
func AddDefaultPackageComment ¶
Adds default autogenerated package comment for a file.
func FindFunction ¶
FindFunction finds a function from given file by given name. Returns nil if structure is not found.
func FindInterface ¶
FindInterface is a function which returns an interface struct from given file by given name. Result of functions is nil if interface with given name is not found in given file structure.
func FindMethod ¶
FindMethod finds a method from given file by given name. Returns nil if structure is not found.
func FindStructure ¶
FindStructure finds a structure from given file by given name. Returns nil if structure is not found.
func IsErrorType ¶
Checks if a given type is a standard error type.
func RegisterGobTypes ¶
func RegisterGobTypes()
Registers specific types for gob encoding/decoding. This work properly this function MUST be called by both client and server.
func RunTestCases ¶
func RunTestCases(t *testing.T, testCases []TestCase, generator Generator, options ...testCaseOption)
Runs test cases based on golden tests. It loads .input file, calls generator with it and after that compares given and .golden file.
func WithGoldenFileGeneration ¶
func WithGoldenFileGeneration() testCaseOption
WithGoldenFileGeneration option regenerages All options is experimental feature. Dont use it if you dont know how it works.
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
It is a plugin client.
func (*Client) Generate ¶
func (g *Client) Generate(params *GenerateParams) (*GenerateResult, error)
Generate method implements Generator interface. It calls plugin generation in special net/rpc format.
type GenerateParams ¶
type GenerateParams struct {
File *types.File
Params json.RawMessage
}
Basic arguments for generator.
type GenerateResult ¶
type GenerateResult struct {
Files []GenerateResultFile
}
Result of generator processing.
type GenerateResultFile ¶
Basic file structure which generator is able to generate.
type Generator ¶
type Generator interface {
Generate(params *GenerateParams) (*GenerateResult, error)
}
Generator is a main core interface. It describes what could be done by the generator.
type NetRPCWorker ¶
type NetRPCWorker struct {
Impl Generator
}
It is a worker for net/rpc.
type PluginGenerateResult ¶
type PluginGenerateResult struct {
GenerateResult *GenerateResult
Error error
}
It is a result of generator plugin work. PluginGenerateResult helps to make solid division between generator error (which is normal) and plugin error (which is outstanding).
type Server ¶
type Server struct {
Impl Generator
}
Server allows to serve a request to plugin.
func (*Server) Generate ¶
func (g *Server) Generate(args *GenerateParams, resp *PluginGenerateResult) error
Generate runs underlying implementation of code generator.