pkg

package
v0.0.0-...-0425162 Latest Latest
Warning

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

Go to latest
Published: May 30, 2019 License: MIT Imports: 14 Imported by: 2

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DefaultHandshakeConfig = plugin.HandshakeConfig{
	ProtocolVersion:  1,
	MagicCookieKey:   "HOST",
	MagicCookieValue: "GEN",
}

DefaultHandshakeConfig useful for plugin compatibility specification.

Functions

func AddDefaultPackageComment

func AddDefaultPackageComment(f *jen.File, generatorName string, version string) *jen.File

Adds default autogenerated package comment for a file.

func FindFunction

func FindFunction(f *types.File, name string) *types.Function

FindFunction finds a function from given file by given name. Returns nil if structure is not found.

func FindInterface

func FindInterface(f *types.File, name string) *types.Interface

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

func FindMethod(f *types.File, name string) *types.Method

FindMethod finds a method from given file by given name. Returns nil if structure is not found.

func FindStructure

func FindStructure(f *types.File, name string) *types.Struct

FindStructure finds a structure from given file by given name. Returns nil if structure is not found.

func IsChanType

func IsChanType(t types.Type) bool

Checks if a given type is a pointer.

func IsErrorType

func IsErrorType(t types.Type) bool

Checks if a given type is a standard error type.

func IsNillableType

func IsNillableType(t types.Type) bool

Checks if a given type may be nil.

func IsPointerType

func IsPointerType(t types.Type) bool

Checks if a given type is a pointer.

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 TypeQual

func TypeQual(currentPackage string, targetPackage string, t types.Type) *jen.Statement

Constructs jennifer statement for given astra type.

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

type GenerateResultFile struct {
	Path    string
	Content []byte
}

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.

func (NetRPCWorker) Client

func (NetRPCWorker) Client(b *plugin.MuxBroker, c *rpc.Client) (interface{}, error)

Returns a client for net/rpc.

func (*NetRPCWorker) Server

func (n *NetRPCWorker) Server(*plugin.MuxBroker) (interface{}, error)

Returns a server 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.

type TestCase

type TestCase struct {
	Name               string
	Params             string
	GeneratedFilePaths []string
}

TestCase is common test case for golden tests.

Jump to

Keyboard shortcuts

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