grpcutil

package
v0.8.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 4, 2026 License: Apache-2.0 Imports: 7 Imported by: 0

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

Constants

This section is empty.

Variables

View Source
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.

func (*GKPluginPlugin) Client

func (p *GKPluginPlugin) Client(b *goplugin.MuxBroker, c *rpc.Client) (interface{}, error)

Client returns the RPC client for the plugin (host side).

func (*GKPluginPlugin) Server

func (p *GKPluginPlugin) Server(b *goplugin.MuxBroker) (interface{}, error)

Server returns the RPC server for the plugin (plugin side).

type GKPluginRPCClient

type GKPluginRPCClient struct {
	// contains filtered or unexported fields
}

GKPluginRPCClient is the RPC client implementation (host side).

func (*GKPluginRPCClient) Call

func (*GKPluginRPCClient) GKRegister

func (c *GKPluginRPCClient) GKRegister() (*plugin.GKRegistration, error)

func (*GKPluginRPCClient) Init

func (c *GKPluginRPCClient) Init(config map[string]string) 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) CacheGet

func (c *HostAPIClient) CacheGet(_ context.Context, key string) ([]byte, bool, error)

CacheGet retrieves a cached value.

func (*HostAPIClient) CacheSet

func (c *HostAPIClient) CacheSet(_ context.Context, key string, value []byte, ttlSeconds int) error

CacheSet stores a cached value with TTL.

func (*HostAPIClient) CallPlugin

func (c *HostAPIClient) CallPlugin(_ context.Context, pluginName, fn string, args json.RawMessage) (json.RawMessage, error)

CallPlugin calls another plugin.

func (*HostAPIClient) ConfigGet

func (c *HostAPIClient) ConfigGet(_ context.Context, key string) (string, error)

ConfigGet retrieves a configuration value.

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) DBExec

func (c *HostAPIClient) DBExec(_ context.Context, query string, args ...any) (int64, error)

DBExec executes a write query via the host's database.

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

func (c *HostAPIClient) EntityRestore(_ context.Context, entityType string, entityID int64) error

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) GetFile added in v0.8.1

func (c *HostAPIClient) GetFile(ctx context.Context, key string) ([]byte, map[string]string, error)

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) ListFiles added in v0.8.1

func (c *HostAPIClient) ListFiles(ctx context.Context, prefix string) ([]plugin.FileInfo, error)

func (*HostAPIClient) Log

func (c *HostAPIClient) Log(_ context.Context, level, message string, fields map[string]any)

Log writes a log entry 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

func (c *HostAPIClient) SecureConfigGet(_ context.Context, key string) (string, error)

SecureConfigGet retrieves a decrypted secret.

func (*HostAPIClient) SecureConfigSet added in v0.8.0

func (c *HostAPIClient) SecureConfigSet(_ context.Context, key string, value string) error

SecureConfigSet stores an encrypted secret.

func (*HostAPIClient) SendEmail

func (c *HostAPIClient) SendEmail(_ context.Context, to, subject, body string, html bool) error

SendEmail sends email via the host.

func (*HostAPIClient) StoreFile added in v0.8.1

func (c *HostAPIClient) StoreFile(ctx context.Context, key string, data []byte, metadata map[string]string) error

func (*HostAPIClient) Translate

func (c *HostAPIClient) Translate(_ context.Context, key string, args ...any) string

Translate returns a translated string for the given key.

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

type InitRequest struct {
	Config    map[string]string
	HostAPIID uint32
}

InitRequest contains initialization data for the plugin.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL