command

package
v0.14.0 Latest Latest
Warning

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

Go to latest
Published: Nov 2, 2026 License: AGPL-3.0 Imports: 11 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package command dispatches plugin-specific opaque command payloads through optional RPC transport.

Index

Constants

View Source
const (
	// PluginID is the go-plugin capability name used to dispense command transport.
	PluginID = "command"
)

Variables

View Source
var (
	// ErrHandlerNotFound is returned when a handler is not found.
	ErrHandlerNotFound = errors.New("handler not found")
	// ErrHandlerTimeout is returned when a handler times out.
	ErrHandlerTimeout = errors.New("handler timeout")
)

Functions

func RegisterPlugin

func RegisterPlugin(
	p *sdk.Plugin,
	opts PluginOpts,
) error

RegisterPlugin installs handlers as a command capability; a nil plugin returns an error.

Types

type Handler

type Handler func(ctx *types.PluginContext, body []byte) ([]byte, error)

Handler is a function that processes a command called from the frontend. It is expected to return the response body as a byte slice.

type Manager

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

Manager dispatches commands through a handler map shared with its constructor.

func NewManager

func NewManager(
	log logging.Logger,
	sp settings.Provider,
	handlers map[string]Handler,
) *Manager

NewManager retains handlers without copying. Do not mutate the map during calls. A nil logger disables logging; handlers own any synchronization they need.

func (*Manager) Call

func (m *Manager) Call(
	ctx *types.PluginContext,
	target string,
	payload []byte,
) ([]byte, error)

Call invokes the exact target handler or returns ErrHandlerNotFound. Payload and result ownership follow the selected handler's contract.

type Plugin

type Plugin struct {
	plugin.Plugin

	Impl Provider
}

Plugin registers command RPCs or creates a client for a go-plugin connection.

func (*Plugin) GRPCClient

func (p *Plugin) GRPCClient(
	_ context.Context,
	_ *plugin.GRPCBroker,
	c *grpc.ClientConn,
) (any, error)

GRPCClient returns a command client using the supplied connection.

func (*Plugin) GRPCServer

func (p *Plugin) GRPCServer(_ *plugin.GRPCBroker, s *grpc.Server) error

GRPCServer installs command RPCs backed by Impl.

type PluginClient

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

PluginClient forwards commands over a shared gRPC client connection.

func (*PluginClient) Call

func (p *PluginClient) Call(
	ctx *types.PluginContext,
	path string,
	body []byte,
) ([]byte, error)

Call forwards a command with request metadata. RPC lifetime uses a background context; cancellation in the supplied PluginContext does not cancel this legacy transport.

type PluginOpts

type PluginOpts struct {
	Handlers map[string]Handler `json:"handlers"`
}

PluginOpts contains the options for the command plugin.

type PluginServer

type PluginServer struct {
	Impl Provider
}

PluginServer adapts command RPCs to Impl without retaining request payloads.

func (*PluginServer) Call

Call requires plugin context and dispatches the requested path. Handler failures become Internal RPC errors; missing context becomes InvalidArgument.

type Provider

type Provider interface {
	Call(ctx *types.PluginContext, target string, payload []byte) ([]byte, error)
}

Provider dispatches opaque command payloads by target. Implementations must coordinate concurrent calls and must not retain or mutate payloads without copying.

Jump to

Keyboard shortcuts

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