1 // The plugin package exposes functions and helpers for communicating to
2 // plugins which are implemented as standalone binary applications.
4 // plugin.Client fully manages the lifecycle of executing the application,
5 // connecting to it, and returning the RPC client for dispensing plugins.
7 // plugin.Serve fully manages listeners to expose an RPC server from a binary
8 // that plugin.Client can connect to.
16 "google.golang.org/grpc"
19 // Plugin is the interface that is implemented to serve/connect to an
20 // inteface implementation.
21 type Plugin interface {
22 // Server should return the RPC server compatible struct to serve
23 // the methods that the Client calls over net/rpc.
24 Server(*MuxBroker) (interface{}, error)
26 // Client returns an interface implementation for the plugin you're
27 // serving that communicates to the server end of the plugin.
28 Client(*MuxBroker, *rpc.Client) (interface{}, error)
31 // GRPCPlugin is the interface that is implemented to serve/connect to
32 // a plugin over gRPC.
33 type GRPCPlugin interface {
34 // GRPCServer should register this plugin for serving with the
35 // given GRPCServer. Unlike Plugin.Server, this is only called once
36 // since gRPC plugins serve singletons.
37 GRPCServer(*GRPCBroker, *grpc.Server) error
39 // GRPCClient should return the interface implementation for the plugin
40 // you're serving via gRPC. The provided context will be canceled by
41 // go-plugin in the event of the plugin process exiting.
42 GRPCClient(context.Context, *GRPCBroker, *grpc.ClientConn) (interface{}, error)
45 // NetRPCUnsupportedPlugin implements Plugin but returns errors for the
46 // Server and Client functions. This will effectively disable support for
47 // net/rpc based plugins.
49 // This struct can be embedded in your struct.
50 type NetRPCUnsupportedPlugin struct{}
52 func (p NetRPCUnsupportedPlugin) Server(*MuxBroker) (interface{}, error) {
53 return nil, errors.New("net/rpc plugin protocol not supported")
56 func (p NetRPCUnsupportedPlugin) Client(*MuxBroker, *rpc.Client) (interface{}, error) {
57 return nil, errors.New("net/rpc plugin protocol not supported")