Documentation ¶
Overview ¶
Package plugin defines the interface for implementing thriftgo plugins.
A plugin is a stand-alone executable that reads input from standard input and writes out generated contents to the standard output while logging any warning messages to the standard error.
When the plugin is executed by thriftgo, the input stream will be a Request object defined in the protocol.thrift serialized with the binary protocol. The plugin is expected to write a Response object to the standard output, serialized with the binary protocol, too. The plugin can use the exit status to indicate whether it finishes its jobs successfully.
The response of a plugin may contains one or more `Generated` contents. Each content can either be a single file -- when its `Name` is set and `InsertionPoint` is not set, or a code segment to be inserted into a file which the `Name` field specifies.
An **insertion point** is a position in a file that a code segment will be inserted before. Sequential segments being inserted to a same point will keep their order. The representation of an insertion point in a file is a string with a special format:
"@@thriftgo_insertion_point(NAME)"
Where NAME is the name of the insertion point that the `InsertionPoint` of a `Generated` could use.
There will be some **pre-defined** insertion points for each backend language. Check the code templates of that language to find out their names.
All insertion points in the file will be erased before thriftgo finally writes out files.
Refer to protocol.thrift for more information.
Index ¶
- Constants
- Variables
- func InsertionPoint(names ...string) string
- func Marshal(data Writer) ([]byte, error)
- func MarshalRequest(data *Request) ([]byte, error)
- func MarshalResponse(data *Response) ([]byte, error)
- func Pack(opts []Option) (ss []string)
- func Unmarshal(data Reader, bs []byte) error
- type Desc
- type Generated
- func (p *Generated) GetContent() string
- func (p *Generated) GetInsertionPoint() string
- func (p *Generated) GetName() string
- func (p *Generated) IsSetInsertionPoint() bool
- func (p *Generated) IsSetName() bool
- func (p *Generated) Read(iprot thrift.TProtocol) (err error)
- func (p *Generated) ReadField1(iprot thrift.TProtocol) error
- func (p *Generated) ReadField2(iprot thrift.TProtocol) error
- func (p *Generated) ReadField3(iprot thrift.TProtocol) error
- func (p *Generated) String() string
- func (p *Generated) Write(oprot thrift.TProtocol) (err error)
- type Option
- type Plugin
- type Reader
- type Request
- func (p *Request) GetAST() *parser.Thrift
- func (p *Request) GetGeneratorParameters() []string
- func (p *Request) GetLanguage() string
- func (p *Request) GetOutputPath() string
- func (p *Request) GetPluginParameters() []string
- func (p *Request) GetRecursive() bool
- func (p *Request) GetVersion() string
- func (p *Request) IsSetAST() bool
- func (p *Request) Read(iprot thrift.TProtocol) (err error)
- func (p *Request) ReadField1(iprot thrift.TProtocol) error
- func (p *Request) ReadField2(iprot thrift.TProtocol) error
- func (p *Request) ReadField3(iprot thrift.TProtocol) error
- func (p *Request) ReadField4(iprot thrift.TProtocol) error
- func (p *Request) ReadField5(iprot thrift.TProtocol) error
- func (p *Request) ReadField6(iprot thrift.TProtocol) error
- func (p *Request) ReadField7(iprot thrift.TProtocol) error
- func (p *Request) String() string
- func (p *Request) Write(oprot thrift.TProtocol) (err error)
- type Response
- func (p *Response) GetContents() []*Generated
- func (p *Response) GetError() string
- func (p *Response) GetWarnings() []string
- func (p *Response) IsSetContents() bool
- func (p *Response) IsSetError() bool
- func (p *Response) IsSetWarnings() bool
- func (p *Response) Read(iprot thrift.TProtocol) (err error)
- func (p *Response) ReadField1(iprot thrift.TProtocol) error
- func (p *Response) ReadField2(iprot thrift.TProtocol) error
- func (p *Response) ReadField3(iprot thrift.TProtocol) error
- func (p *Response) String() string
- func (p *Response) Write(oprot thrift.TProtocol) (err error)
- type Writer
Constants ¶
const InsertionPointFormat = "@@thriftgo_insertion_point(%s)"
InsertionPointFormat is the format for insertion points.
Variables ¶
var Generated_InsertionPoint_DEFAULT string
var Generated_Name_DEFAULT string
var MaxExecutionTime = time.Minute
MaxExecutionTime is a timeout for executing external plugins.
var Request_AST_DEFAULT *parser.Thrift
var Response_Contents_DEFAULT []*Generated
var Response_Error_DEFAULT string
var Response_Warnings_DEFAULT []string
Functions ¶
func InsertionPoint ¶
InsertionPoint returns a new insertion point.
func MarshalRequest ¶
MarshalRequest encodes a request with binary protocol.
func MarshalResponse ¶
MarshalResponse encodes a response with binary protocol.
Types ¶
type Desc ¶
Desc can be used to describes the interface of a plugin or a generator backend.
func ParseCompactArguments ¶
ParseCompactArguments parses a compact form option into arguments. A compact form option is like:
name:key1=val1,key2,key3=val3
This function barely checks the validity of the string, so the user should always provide a valid input.
type Generated ¶
type Generated struct { Content string `thrift:"Content,1,required" json:"Content"` Name *string `thrift:"Name,2" json:"Name,omitempty"` InsertionPoint *string `thrift:"InsertionPoint,3" json:"InsertionPoint,omitempty"` }
func NewGenerated ¶
func NewGenerated() *Generated
func (*Generated) GetContent ¶
func (*Generated) GetInsertionPoint ¶
func (*Generated) IsSetInsertionPoint ¶
type Plugin ¶
type Plugin interface { // Name returns the name of the plugin. Name() string // Execute invokes the plugin and waits for response. Execute(req *Request) (res *Response) }
Plugin takes a request and builds a response to generate codes.
type Request ¶
type Request struct { Version string `thrift:"Version,1,required" json:"Version"` GeneratorParameters []string `thrift:"GeneratorParameters,2,required" json:"GeneratorParameters"` PluginParameters []string `thrift:"PluginParameters,3,required" json:"PluginParameters"` Language string `thrift:"Language,4,required" json:"Language"` OutputPath string `thrift:"OutputPath,5,required" json:"OutputPath"` Recursive bool `thrift:"Recursive,6,required" json:"Recursive"` AST *parser.Thrift `thrift:"AST,7,required" json:"AST"` }
func NewRequest ¶
func NewRequest() *Request
func UnmarshalRequest ¶
UnmarshalRequest decodes a request with binary protocol.
func (*Request) GetGeneratorParameters ¶
func (*Request) GetLanguage ¶
func (*Request) GetOutputPath ¶
func (*Request) GetPluginParameters ¶
func (*Request) GetRecursive ¶
func (*Request) GetVersion ¶
type Response ¶
type Response struct { Error *string `thrift:"Error,1" json:"Error,omitempty"` Contents []*Generated `thrift:"Contents,2" json:"Contents,omitempty"` Warnings []string `thrift:"Warnings,3" json:"Warnings,omitempty"` }
func BuildErrorResponse ¶
BuildErrorResponse creates a plugin response with a error message.
func NewResponse ¶
func NewResponse() *Response
func UnmarshalResponse ¶
UnmarshalResponse decodes a response with binary protocol.