Documentation
¶
Overview ¶
Package grpcutil provides shared types for gRPC plugin communication. This file provides the plugin-side HostAPI client that allows plugins to call back to the GoatFlow host for database, cache, and other operations.
Package grpcutil provides the gRPC plugin serving utilities for GoatKit.
External gRPC plugins import this package to serve their implementation. The host-side loading and management stays in internal/plugin/grpc.
Usage:
func main() {
grpcutil.ServePlugin(&MyPlugin{})
}
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 *[]byte) error
- func (s *GKPluginRPCServer) Init(req InitRequest, resp *interface{}) error
- func (s *GKPluginRPCServer) Shutdown(args interface{}, resp *interface{}) error
- type GKPluginWithHost
- type HostAPIClient
- func (c *HostAPIClient) CacheDelete(_ context.Context, key string) error
- func (c *HostAPIClient) CacheGet(_ context.Context, key string) ([]byte, bool, error)
- func (c *HostAPIClient) CacheSet(_ context.Context, key string, value []byte, ttlSeconds int) error
- func (c *HostAPIClient) CallPlugin(_ context.Context, pluginName, fn string, args json.RawMessage) (json.RawMessage, error)
- func (c *HostAPIClient) ConfigGet(_ context.Context, key string) (string, error)
- func (c *HostAPIClient) CustomFieldsGet(_ context.Context, entityType string, objectID int64, fields []string) (map[string]any, error)
- func (c *HostAPIClient) CustomFieldsQuery(_ context.Context, entityType string, filters []plugin.CustomFieldFilter) ([]int64, error)
- func (c *HostAPIClient) CustomFieldsSet(_ context.Context, entityType string, objectID int64, values map[string]any) error
- func (c *HostAPIClient) DBExec(_ context.Context, query string, args ...any) (int64, error)
- func (c *HostAPIClient) DBQuery(_ context.Context, query string, args ...any) ([]map[string]any, error)
- func (c *HostAPIClient) DeleteFile(ctx context.Context, key string) error
- func (c *HostAPIClient) EntityHardDelete(_ context.Context, entityType string, entityID int64, reason string) error
- func (c *HostAPIClient) EntityRestore(_ context.Context, entityType string, entityID int64) error
- func (c *HostAPIClient) EntitySoftDelete(_ context.Context, entityType string, entityID int64, reason string) error
- func (c *HostAPIClient) GetFile(ctx context.Context, key string) ([]byte, map[string]string, error)
- func (c *HostAPIClient) HTTPRequest(_ context.Context, method, url string, headers map[string]string, body []byte) (int, []byte, error)
- func (c *HostAPIClient) ListFiles(ctx context.Context, prefix string) ([]plugin.FileInfo, error)
- func (c *HostAPIClient) Log(_ context.Context, level, message string, fields map[string]any)
- func (c *HostAPIClient) OrgID(_ context.Context) int64
- func (c *HostAPIClient) PublishEvent(_ context.Context, channel string, eventType string, data string) error
- func (c *HostAPIClient) RecycleBinList(_ context.Context, entityType string) (json.RawMessage, error)
- func (c *HostAPIClient) SecureConfigGet(_ context.Context, key string) (string, error)
- func (c *HostAPIClient) SecureConfigSet(_ context.Context, key string, value string) error
- func (c *HostAPIClient) SendEmail(_ context.Context, to, subject, body string, html bool) error
- func (c *HostAPIClient) StoreFile(ctx context.Context, key string, data []byte, metadata map[string]string) error
- func (c *HostAPIClient) Translate(_ context.Context, key string, args ...any) string
- type HostAPIRPCRequest
- type HostAPIRPCResponse
- type InitRequest
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.
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. Plugins that need HostAPI access should also implement GKPluginWithHost.
type GKPluginPlugin ¶
type GKPluginPlugin struct {
goplugin.Plugin
Impl GKPluginInterface
}
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 *[]byte) 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 GKPluginWithHost ¶
type GKPluginWithHost interface {
GKPluginInterface
InitWithHost(config map[string]string, host plugin.HostAPI) error
}
GKPluginWithHost is an optional interface plugins implement to receive the host's HostAPI during initialization. This allows plugins to use the platform's database, cache, HTTP, email, and other services.
type HostAPIClient ¶
type HostAPIClient struct {
// contains filtered or unexported fields
}
HostAPIClient implements plugin.HostAPI by making RPC calls back to the host. Plugins use this to access database, cache, HTTP, email, config, and i18n.
func NewHostAPIClient ¶
func NewHostAPIClient(client *rpc.Client, pluginName string) *HostAPIClient
NewHostAPIClient creates a new HostAPI client for plugin-to-host RPC calls.
func (*HostAPIClient) CacheDelete ¶
func (c *HostAPIClient) CacheDelete(_ context.Context, key string) error
CacheDelete removes a cached value.
func (*HostAPIClient) CallPlugin ¶
func (c *HostAPIClient) CallPlugin(_ context.Context, pluginName, fn string, args json.RawMessage) (json.RawMessage, error)
CallPlugin calls another plugin.
func (*HostAPIClient) CustomFieldsGet ¶ added in v0.8.0
func (c *HostAPIClient) CustomFieldsGet(_ context.Context, entityType string, objectID int64, fields []string) (map[string]any, error)
CustomFieldsGet retrieves custom field values for an entity.
func (*HostAPIClient) CustomFieldsQuery ¶ added in v0.8.0
func (c *HostAPIClient) CustomFieldsQuery(_ context.Context, entityType string, filters []plugin.CustomFieldFilter) ([]int64, error)
CustomFieldsQuery finds entities by custom field values.
func (*HostAPIClient) CustomFieldsSet ¶ added in v0.8.0
func (c *HostAPIClient) CustomFieldsSet(_ context.Context, entityType string, objectID int64, values map[string]any) error
CustomFieldsSet stores custom field values for an entity.
func (*HostAPIClient) DBQuery ¶
func (c *HostAPIClient) DBQuery(_ context.Context, query string, args ...any) ([]map[string]any, error)
DBQuery executes a read query via the host's database.
func (*HostAPIClient) DeleteFile ¶ added in v0.8.1
func (c *HostAPIClient) DeleteFile(ctx context.Context, key string) error
func (*HostAPIClient) EntityHardDelete ¶ added in v0.8.0
func (c *HostAPIClient) EntityHardDelete(_ context.Context, entityType string, entityID int64, reason string) error
EntityHardDelete permanently removes an entity.
func (*HostAPIClient) EntityRestore ¶ added in v0.8.0
EntityRestore restores a soft-deleted entity.
func (*HostAPIClient) EntitySoftDelete ¶ added in v0.8.0
func (c *HostAPIClient) EntitySoftDelete(_ context.Context, entityType string, entityID int64, reason string) error
EntitySoftDelete soft-deletes an entity.
func (*HostAPIClient) HTTPRequest ¶
func (c *HostAPIClient) HTTPRequest(_ context.Context, method, url string, headers map[string]string, body []byte) (int, []byte, error)
HTTPRequest makes an HTTP request via the host.
func (*HostAPIClient) OrgID ¶ added in v0.8.0
func (c *HostAPIClient) OrgID(_ context.Context) int64
OrgID returns the active organisation ID.
func (*HostAPIClient) PublishEvent ¶
func (c *HostAPIClient) PublishEvent(_ context.Context, channel string, eventType string, data string) error
PublishEvent sends an SSE event to a named channel for connected browser clients.
func (*HostAPIClient) RecycleBinList ¶ added in v0.8.0
func (c *HostAPIClient) RecycleBinList(_ context.Context, entityType string) (json.RawMessage, error)
RecycleBinList lists soft-deleted entities.
func (*HostAPIClient) SecureConfigGet ¶ added in v0.8.0
SecureConfigGet retrieves a decrypted secret.
func (*HostAPIClient) SecureConfigSet ¶ added in v0.8.0
SecureConfigSet stores an encrypted secret.
type HostAPIRPCRequest ¶
type HostAPIRPCRequest struct {
Method string `json:"method"`
Args json.RawMessage `json:"args"`
CallerPlugin string `json:"caller_plugin"`
}
HostAPIRPCRequest is a generic host API request.
type HostAPIRPCResponse ¶
type HostAPIRPCResponse struct {
Result json.RawMessage `json:"result"`
Error string `json:"error"`
}
HostAPIRPCResponse is a generic host API response.
type InitRequest ¶
InitRequest contains initialization data for the plugin.