Documentation
¶
Overview ¶
Package grpc provides gRPC-based plugin runtime using HashiCorp go-plugin.
This enables native Go plugins to run as separate processes, communicating with the host via gRPC. Useful for I/O-heavy plugins that benefit from native performance and direct system access.
Index ¶
- Variables
- func ServePlugin(impl GKPluginInterface)
- type CallRequest
- type CallResponse
- type GKPluginInterface
- type GKPluginPlugin
- type GKPluginRPCClient
- type GKPluginRPCServer
- func (s *GKPluginRPCServer) Call(req CallRequest, resp *CallResponse) error
- func (s *GKPluginRPCServer) GKRegister(args interface{}, resp *plugin.GKRegistration) error
- func (s *GKPluginRPCServer) Init(req InitRequest, resp *interface{}) error
- func (s *GKPluginRPCServer) Shutdown(args interface{}, resp *interface{}) error
- type GRPCPlugin
- type HostAPIRPCClient
- func (c *HostAPIRPCClient) Call(method string, args any) (json.RawMessage, error)
- func (c *HostAPIRPCClient) CallPlugin(pluginName, fn string, args json.RawMessage) (json.RawMessage, error)
- func (c *HostAPIRPCClient) DBExec(query string, args ...any) (int64, error)
- func (c *HostAPIRPCClient) DBQuery(query string, args ...any) ([]map[string]any, error)
- type HostAPIRPCServer
- type HostAPIRequest
- type HostAPIResponse
- type HostError
- type InitRequest
- type UnknownMethodError
Constants ¶
This section is empty.
Variables ¶
var Handshake = goplugin.HandshakeConfig{
ProtocolVersion: 1,
MagicCookieKey: "GOATKIT_PLUGIN",
MagicCookieValue: "goatkit-v1",
}
Handshake is the shared handshake config for host and plugins. Plugins must use the same values to connect.
var PluginMap = map[string]goplugin.Plugin{ "gkplugin": &GKPluginPlugin{}, }
PluginMap is the map of plugin types we support.
Functions ¶
func ServePlugin ¶
func ServePlugin(impl GKPluginInterface)
ServePlugin is called by plugin executables to serve the plugin. Plugin main() should call this with their implementation.
Types ¶
type CallRequest ¶
type CallRequest struct {
Function string
Args json.RawMessage
}
CallRequest is the RPC request for Call.
type CallResponse ¶
type CallResponse struct {
Result json.RawMessage
Error string
}
CallResponse is the RPC response for Call.
type GKPluginInterface ¶
type GKPluginInterface interface {
GKRegister() (*plugin.GKRegistration, error)
Init(config map[string]string) error
Call(fn string, args json.RawMessage) (json.RawMessage, error)
Shutdown() error
}
GKPluginInterface is the interface that gRPC plugins implement. This is the RPC interface - the actual implementation runs in the plugin process.
type GKPluginPlugin ¶
type GKPluginPlugin struct {
goplugin.Plugin
Impl GKPluginInterface
Host plugin.HostAPI // For bidirectional calls
}
GKPluginPlugin is the go-plugin.Plugin implementation.
type GKPluginRPCClient ¶
type GKPluginRPCClient struct {
// contains filtered or unexported fields
}
GKPluginRPCClient is the RPC client implementation (host side).
func (*GKPluginRPCClient) Call ¶
func (c *GKPluginRPCClient) Call(fn string, args json.RawMessage) (json.RawMessage, error)
func (*GKPluginRPCClient) GKRegister ¶
func (c *GKPluginRPCClient) GKRegister() (*plugin.GKRegistration, error)
func (*GKPluginRPCClient) Shutdown ¶
func (c *GKPluginRPCClient) Shutdown() error
type GKPluginRPCServer ¶
type GKPluginRPCServer struct {
Impl GKPluginInterface
// contains filtered or unexported fields
}
GKPluginRPCServer is the RPC server implementation (plugin side).
func (*GKPluginRPCServer) Call ¶
func (s *GKPluginRPCServer) Call(req CallRequest, resp *CallResponse) error
func (*GKPluginRPCServer) GKRegister ¶
func (s *GKPluginRPCServer) GKRegister(args interface{}, resp *plugin.GKRegistration) error
func (*GKPluginRPCServer) Init ¶
func (s *GKPluginRPCServer) Init(req InitRequest, resp *interface{}) error
func (*GKPluginRPCServer) Shutdown ¶
func (s *GKPluginRPCServer) Shutdown(args interface{}, resp *interface{}) error
type GRPCPlugin ¶
type GRPCPlugin struct {
// contains filtered or unexported fields
}
GRPCPlugin wraps a go-plugin client to implement plugin.Plugin.
func LoadGRPCPlugin ¶
func LoadGRPCPlugin(execPath string, host plugin.HostAPI) (*GRPCPlugin, error)
LoadGRPCPlugin loads a gRPC plugin from an executable path.
func (*GRPCPlugin) Call ¶
func (p *GRPCPlugin) Call(ctx context.Context, fn string, args json.RawMessage) (json.RawMessage, error)
Call implements plugin.Plugin.
func (*GRPCPlugin) GKRegister ¶
func (p *GRPCPlugin) GKRegister() plugin.GKRegistration
GKRegister implements plugin.Plugin.
type HostAPIRPCClient ¶
type HostAPIRPCClient struct {
// contains filtered or unexported fields
}
HostAPIRPCClient is the client plugins use to call the host. This runs on the plugin side.
func NewHostAPIRPCClient ¶
func NewHostAPIRPCClient(client *rpc.Client) *HostAPIRPCClient
NewHostAPIRPCClient creates a new host API client.
func (*HostAPIRPCClient) Call ¶
func (c *HostAPIRPCClient) Call(method string, args any) (json.RawMessage, error)
Call makes a host API call.
func (*HostAPIRPCClient) CallPlugin ¶
func (c *HostAPIRPCClient) CallPlugin(pluginName, fn string, args json.RawMessage) (json.RawMessage, error)
type HostAPIRPCServer ¶
HostAPIRPCServer exposes HostAPI to plugins via RPC. This runs on the host side and handles plugin callbacks.
func (*HostAPIRPCServer) Call ¶
func (s *HostAPIRPCServer) Call(req HostAPIRequest, resp *HostAPIResponse) error
Call handles all host API calls from plugins.
type HostAPIRequest ¶
type HostAPIRequest struct {
Method string // Method name (e.g., "db_query", "cache_get")
Args json.RawMessage // JSON-encoded arguments
CallerPlugin string // Name of the calling plugin (for error context)
}
HostAPIRequest is a generic host API request.
type HostAPIResponse ¶
type HostAPIResponse struct {
Result json.RawMessage
Error string
}
HostAPIResponse is a generic host API response.
type HostError ¶
type HostError struct {
Message string
}
HostError represents an error from the host.
type InitRequest ¶
type InitRequest struct {
Config map[string]string
HostAPIID uint32 // Broker ID for calling back to host
}
InitRequest contains initialization data for the plugin.
type UnknownMethodError ¶
type UnknownMethodError struct {
Method string
}
UnknownMethodError is returned when a plugin calls an unknown host method.
func (*UnknownMethodError) Error ¶
func (e *UnknownMethodError) Error() string