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/platform/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 GKPluginWithContext
- type GKPluginWithHost
- type HostAPIClient
- func (c *HostAPIClient) CacheDelete(ctx context.Context, key string) error
- func (c *HostAPIClient) CacheGet(ctx context.Context, key string) ([]byte, bool, error)
- func (c *HostAPIClient) CacheSet(ctx context.Context, key string, value []byte, ttlSeconds int) error
- func (c *HostAPIClient) CallPlugin(ctx context.Context, pluginName, fn string, args json.RawMessage) (json.RawMessage, error)
- func (c *HostAPIClient) ChangeTicketStatus(ctx context.Context, ticketID, stateID, userID int64, untilTime int64) error
- func (c *HostAPIClient) ConfigGet(ctx context.Context, key string) (string, error)
- func (c *HostAPIClient) CreateArticle(ctx context.Context, ticketID, createdBy int64, subject, body string, ...) (int64, error)
- func (c *HostAPIClient) CreateArticleAttachment(ctx context.Context, articleID, createdBy int64, filename, contentType string, ...) (int64, error)
- func (c *HostAPIClient) CustomFieldsGet(ctx context.Context, entityType string, objectID int64, fields []string) (map[string]any, error)
- func (c *HostAPIClient) CustomFieldsQuery(ctx context.Context, entityType string, filters []plugin.CustomFieldFilter) ([]int64, error)
- func (c *HostAPIClient) CustomFieldsSet(ctx context.Context, entityType string, objectID int64, values map[string]any) error
- func (c *HostAPIClient) DBExec(ctx context.Context, query string, args ...any) (int64, error)
- func (c *HostAPIClient) DBQuery(ctx context.Context, query string, args ...any) ([]map[string]any, error)
- func (c *HostAPIClient) DeleteArticleAttachment(ctx context.Context, articleID, attachmentID int64) error
- func (c *HostAPIClient) DeleteFile(ctx context.Context, key string) error
- func (c *HostAPIClient) EntityHardDelete(ctx context.Context, entityType string, entityID int64, reason string) error
- func (c *HostAPIClient) EntityRestore(ctx context.Context, entityType string, entityID int64) error
- func (c *HostAPIClient) EntitySoftDelete(ctx context.Context, entityType string, entityID int64, reason string) error
- func (c *HostAPIClient) GenerateThumbnail(ctx context.Context, data []byte, contentType string, maxWidth, maxHeight int) ([]byte, string, error)
- func (c *HostAPIClient) GetFile(ctx context.Context, key string) ([]byte, map[string]string, error)
- func (c *HostAPIClient) HTTPRequest(ctx context.Context, method, url string, headers map[string]string, ...) (int, []byte, error)
- func (c *HostAPIClient) ListArticleAttachments(ctx context.Context, articleID int64) ([]plugin.ArticleAttachment, error)
- func (c *HostAPIClient) ListFiles(ctx context.Context, prefix string) ([]plugin.FileInfo, error)
- func (c *HostAPIClient) ListTicketStates(ctx context.Context) ([]plugin.TicketStateInfo, error)
- func (c *HostAPIClient) ListTicketViews(ctx context.Context) ([]plugin.TicketViewInfo, error)
- func (c *HostAPIClient) Log(ctx context.Context, level, message string, fields map[string]any)
- func (c *HostAPIClient) OrgID(ctx context.Context) int64
- func (c *HostAPIClient) PublishEvent(ctx context.Context, channel string, eventType string, data string) error
- func (c *HostAPIClient) RecycleBinList(ctx context.Context, entityType string) (json.RawMessage, error)
- func (c *HostAPIClient) RenderMarkdownToPdf(ctx context.Context, markdown string, options plugin.PdfRenderOptions) ([]byte, error)
- func (c *HostAPIClient) SecureConfigGet(ctx context.Context, key string) (string, error)
- func (c *HostAPIClient) SecureConfigSet(ctx context.Context, key string, value string) error
- func (c *HostAPIClient) SendEmail(ctx 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(ctx 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
CallToken string
}
CallRequest is the RPC request for Call. CallToken identifies the host call; HostAPI callbacks send it back to run in the call's context.
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 GKPluginWithContext ¶ added in v0.10.0
type GKPluginWithContext interface {
CallWithContext(ctx context.Context, fn string, args json.RawMessage) (json.RawMessage, error)
}
GKPluginWithContext is an optional interface. When a plugin implements it, the host calls CallWithContext instead of Call. ctx carries the host call's identity: HostAPI calls made with ctx (or a context derived from it) run in the host with the call's context, so the host records the acting user (the caller's _user_id) for actions such as EntitySoftDelete, applies the request language to Translate and enforces the call's deadline. HostAPI calls made with an unrelated context run as system actions.
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. A ctx received in GKPluginWithContext.CallWithContext (or derived from it) ties each call to the host call it belongs to; see GKPluginWithContext.
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(ctx context.Context, key string) error
CacheDelete removes a cached value.
func (*HostAPIClient) CacheSet ¶
func (c *HostAPIClient) CacheSet(ctx context.Context, key string, value []byte, ttlSeconds int) error
CacheSet stores a cached value with TTL.
func (*HostAPIClient) CallPlugin ¶
func (c *HostAPIClient) CallPlugin(ctx context.Context, pluginName, fn string, args json.RawMessage) (json.RawMessage, error)
CallPlugin calls another plugin.
func (*HostAPIClient) ChangeTicketStatus ¶ added in v0.10.0
func (c *HostAPIClient) ChangeTicketStatus(ctx context.Context, ticketID, stateID, userID int64, untilTime int64) error
ChangeTicketStatus changes a ticket's state with core semantics.
func (*HostAPIClient) CreateArticle ¶ added in v0.10.0
func (c *HostAPIClient) CreateArticle(ctx context.Context, ticketID, createdBy int64, subject, body string, visibleToCustomer bool) (int64, error)
CreateArticle creates an article (note/transcript/deliverable) on a ticket.
func (*HostAPIClient) CreateArticleAttachment ¶ added in v0.10.0
func (c *HostAPIClient) CreateArticleAttachment(ctx context.Context, articleID, createdBy int64, filename, contentType string, content []byte) (int64, error)
CreateArticleAttachment attaches a file to an article's thread.
func (*HostAPIClient) CustomFieldsGet ¶ added in v0.8.0
func (c *HostAPIClient) CustomFieldsGet(ctx 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(ctx 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(ctx 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(ctx context.Context, query string, args ...any) ([]map[string]any, error)
DBQuery executes a read query via the host's database.
func (*HostAPIClient) DeleteArticleAttachment ¶ added in v0.10.0
func (c *HostAPIClient) DeleteArticleAttachment(ctx context.Context, articleID, attachmentID int64) error
DeleteArticleAttachment removes one attachment from an article.
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(ctx 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(ctx context.Context, entityType string, entityID int64, reason string) error
EntitySoftDelete soft-deletes an entity.
func (*HostAPIClient) GenerateThumbnail ¶ added in v0.9.0
func (*HostAPIClient) HTTPRequest ¶
func (c *HostAPIClient) HTTPRequest(ctx context.Context, method, url string, headers map[string]string, body []byte) (int, []byte, error)
HTTPRequest makes an HTTP request via the host.
func (*HostAPIClient) ListArticleAttachments ¶ added in v0.10.0
func (c *HostAPIClient) ListArticleAttachments(ctx context.Context, articleID int64) ([]plugin.ArticleAttachment, error)
ListArticleAttachments returns metadata for an article's attachments.
func (*HostAPIClient) ListTicketStates ¶ added in v0.10.0
func (c *HostAPIClient) ListTicketStates(ctx context.Context) ([]plugin.TicketStateInfo, error)
ListTicketStates returns all valid ticket states with type info.
func (*HostAPIClient) ListTicketViews ¶ added in v0.10.0
func (c *HostAPIClient) ListTicketViews(ctx context.Context) ([]plugin.TicketViewInfo, error)
ListTicketViews returns the ticket-view URL templates declared by the enabled plugins.
func (*HostAPIClient) OrgID ¶ added in v0.8.0
func (c *HostAPIClient) OrgID(ctx context.Context) int64
OrgID returns the active organisation ID.
func (*HostAPIClient) PublishEvent ¶
func (c *HostAPIClient) PublishEvent(ctx 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(ctx context.Context, entityType string) (json.RawMessage, error)
RecycleBinList lists soft-deleted entities.
func (*HostAPIClient) RenderMarkdownToPdf ¶ added in v0.10.0
func (c *HostAPIClient) RenderMarkdownToPdf(ctx context.Context, markdown string, options plugin.PdfRenderOptions) ([]byte, error)
RenderMarkdownToPdf renders a markdown document to PDF bytes via the host.
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"`
CallToken string `json:"call_token"`
}
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.