Help us shape the future of Go! Take the 2026 Go Developer Survey

plugin

package
v0.8.2 Latest Latest
Warning

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

Go to latest
Published: Oct 19, 2026 License: GPL-3.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const MetadataCapability = "metadata"

MetadataCapability is the manifest capability string that enables the metadata protocol. Plugins declaring it must serve the "metadata" plugin from their Serve config.

Variables

View Source
var HandshakeConfig = hplugin.HandshakeConfig{
	ProtocolVersion:  2,
	MagicCookieKey:   "CHEST_PLUGIN",
	MagicCookieValue: "CHEST_IN_A_CHEST",
}

HandshakeConfig ensures plugin and host agree on protocol. ProtocolVersion 2 adds the metadata capability (Inspect RPC); plugins built against protocol 1 must be recompiled.

View Source
var MetadataPluginMap = map[string]hplugin.Plugin{
	"metadata": &MetadataPluginRPC{},
}

MetadataPluginMap is the plugin-map entry hosts and plugins merge into their Serve config to expose the metadata protocol alongside the classifier protocol.

View Source
var PluginMap = map[string]hplugin.Plugin{
	"classifier": &ClassifierPluginRPC{},
}

PluginMap maps plugin types to implementations

Functions

func ClassifyWithPlugins

func ClassifyWithPlugins(services []ClassifierService, filename, ext string) string

ClassifyWithPlugins tries each loaded plugin service to classify a file. Returns the first non-empty, non-"Other" result, or empty string if no plugin matched.

func EnrichWithPlugins added in v0.4.1

func EnrichWithPlugins(services []MetadataService, sample models.FileSample) models.FileMetadata

EnrichWithPlugins runs a file sample through each loaded metadata plugin in order, merging the first non-empty value produced for every field. Fields set by an earlier plugin win; later plugins only fill gaps. The returned models.FileMetadata reports only values that came from plugins, so callers can distinguish plugin output from built-in detection. Plugin errors are ignored — enrichment is best-effort by design.

func SampleFromFile added in v0.4.1

func SampleFromFile(file models.File) models.FileSample

SampleFromFile builds a bounded models.FileSample for a scanned file, reading the first pluginSampleHeadBytes and last pluginSampleTailBytes of file content so plugins can sniff signatures. Read errors are non-fatal: the sample is returned without content bytes if the file cannot be read.

Types

type ClassifierPluginRPC

type ClassifierPluginRPC struct {
	Impl ClassifierService
}

func (*ClassifierPluginRPC) Client

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

func (*ClassifierPluginRPC) Server

func (p *ClassifierPluginRPC) Server(*hplugin.MuxBroker) (interface{}, error)

type ClassifierRPCClient

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

RPC Server/Client implementation

func (*ClassifierRPCClient) Classify

func (c *ClassifierRPCClient) Classify(filename string, ext string) (string, error)

func (*ClassifierRPCClient) GetCustomRules

func (c *ClassifierRPCClient) GetCustomRules() ([]models.Rule, error)

func (*ClassifierRPCClient) GetInfo

func (c *ClassifierRPCClient) GetInfo() (Manifest, error)

type ClassifierRPCServer

type ClassifierRPCServer struct {
	Impl ClassifierService
}

func (*ClassifierRPCServer) Classify

func (s *ClassifierRPCServer) Classify(args []string, resp *string) error

func (*ClassifierRPCServer) GetCustomRules

func (s *ClassifierRPCServer) GetCustomRules(args interface{}, resp *[]models.Rule) error

func (*ClassifierRPCServer) GetInfo

func (s *ClassifierRPCServer) GetInfo(args interface{}, resp *Manifest) error

type ClassifierService

type ClassifierService interface {
	GetInfo() (Manifest, error)
	Classify(filename string, ext string) (string, error)
	GetCustomRules() ([]models.Rule, error)
}

ClassifierService is the interface exposed by plugins

type Manager

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

Manager discovers and manages local plugins

func NewManager

func NewManager(customDir ...string) (*Manager, error)

NewManager creates a plugin manager pointing to target directory (default ~/.chest/plugins)

func (*Manager) GetInfo

func (m *Manager) GetInfo(name string) (*Manifest, error)

GetInfo retrieves manifest for specific plugin

func (*Manager) GetPluginDir

func (m *Manager) GetPluginDir() string

GetPluginDir returns plugin storage folder

func (*Manager) Install

func (m *Manager) Install(sourcePath string) (*Manifest, error)

Install installs a plugin from a local directory containing manifest.toml or manifest.json

func (*Manager) List

func (m *Manager) List() ([]Manifest, error)

List installed plugins by reading manifest.toml or manifest.json in each plugin folder

func (*Manager) LoadAllClassifiers

func (m *Manager) LoadAllClassifiers() ([]ClassifierService, []models.Rule, func())

LoadAllClassifiers discovers all installed plugins with "classifier" capability, spawns each one, collects custom rules via GetCustomRules(), and returns:

  • services: slice of active ClassifierService instances
  • rules: aggregated custom rules from all plugins
  • cleanup: function to kill all spawned plugin processes

func (*Manager) LoadAllMetadata added in v0.4.1

func (m *Manager) LoadAllMetadata() ([]MetadataService, func())

LoadAllMetadata spawns every installed plugin declaring the "metadata" capability and returns ready-to-use services plus a single cleanup that kills all spawned plugin processes. Broken plugins are skipped silently so one bad install never blocks a sort or search run.

func (*Manager) LoadClassifier

func (m *Manager) LoadClassifier(name string) (ClassifierService, func(), error)

LoadClassifier spawns external plugin process and returns client

func (*Manager) LoadMetadata added in v0.4.1

func (m *Manager) LoadMetadata(name string) (MetadataService, func(), error)

LoadMetadata spawns a single metadata plugin process and returns its client plus a cleanup function that terminates the process.

func (*Manager) Remove

func (m *Manager) Remove(name string) error

Remove uninstalls a plugin

type Manifest

type Manifest struct {
	Name         string   `json:"name" toml:"name"`
	Version      string   `json:"version" toml:"version"`
	Description  string   `json:"description" toml:"description"`
	Author       string   `json:"author,omitempty" toml:"author,omitempty"`
	Capabilities []string `json:"capabilities" toml:"capabilities"` // e.g. ["classifier", "metadata", "preset", "rule"]
	Binary       string   `json:"binary" toml:"binary"`             // executable filename
}

Manifest represents plugin metadata stored in manifest.json, manifest.toml, or returned by plugin

type MetadataPluginRPC added in v0.4.1

type MetadataPluginRPC struct {
	Impl MetadataService
}

MetadataPluginRPC adapts MetadataService to the go-plugin machinery.

func (*MetadataPluginRPC) Client added in v0.4.1

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

func (*MetadataPluginRPC) Server added in v0.4.1

func (p *MetadataPluginRPC) Server(*hplugin.MuxBroker) (interface{}, error)

type MetadataRPCClient added in v0.4.1

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

MetadataRPCClient is the host-side RPC implementation of MetadataService.

func (*MetadataRPCClient) GetInfo added in v0.4.1

func (c *MetadataRPCClient) GetInfo() (Manifest, error)

func (*MetadataRPCClient) Inspect added in v0.4.1

type MetadataRPCServer added in v0.4.1

type MetadataRPCServer struct {
	Impl MetadataService
}

MetadataRPCServer is the plugin-side RPC server wrapping a MetadataService.

func (*MetadataRPCServer) GetInfo added in v0.4.1

func (s *MetadataRPCServer) GetInfo(args interface{}, resp *Manifest) error

func (*MetadataRPCServer) Inspect added in v0.4.1

func (s *MetadataRPCServer) Inspect(sample models.FileSample, resp *models.FileMetadata) error

type MetadataService added in v0.4.1

type MetadataService interface {
	GetInfo() (Manifest, error)
	Inspect(sample models.FileSample) (models.FileMetadata, error)
}

MetadataService is the interface exposed by plugins with the "metadata" capability. GetInfo mirrors ClassifierService.GetInfo so hosts can verify identity over RPC; Inspect enriches a bounded file sample with format, MIME, category, embedded dates and arbitrary metadata fields.

Jump to

Keyboard shortcuts

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