core

package
v0.12.0 Latest Latest
Warning

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

Go to latest
Published: Nov 17, 2026 License: MIT Imports: 10 Imported by: ? 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 core chooses which implementation of the plugin engine runs a program's sessions.

The engine's rules exist three times, and each is its own module so an application takes only the ones it needs:

go    the pure-Go engine (pkg/ext-go/engine): the oracle the others are held against, and
      the one that exists on every platform
cgo   the C engine through cgo (pkg/ext-go/cgoengine): the C itself, at native speed
c2go  the C engine translated to Go by ccgo (pkg/ext-go/c2goengine): no cgo and no C compiler

This package is the one place that knows all three. Engines lists them in the order Choose prefers them; Choose picks one by name or, without a name, the best available one that has the features the caller needs; FromEnvironment reads the name from EXT_ENGINE. The choice is made once, when a session or an instance manager is opened, and it is visible: Session.Engine names the engine that runs the session. An engine is never replaced by another halfway through a session, and Choose never falls back silently: a name that cannot be served is an error.

Index

Constants

View Source
const Environment = "EXT_ENGINE"

Environment is the variable FromEnvironment reads: an engine name, or auto (the default).

Variables

This section is empty.

Functions

This section is empty.

Types

type Engine

type Engine interface {
	// Name says which engine this is.
	Name() Name
	// Available reports whether this build holds the engine: the cgo engine needs cgo, the
	// ext_cengine tag and the C library; the translated engine needs a platform it was translated for.
	Available() bool
	// Features is what the engine carries here; none when it is not available.
	Features() Feature

	// Call runs one of the engine's pure services on bounded JSON. No plugin is executed. It needs
	// Services; see lib/plugin/services.md for the services.
	Call(operation string, input json.RawMessage) (json.RawMessage, error)
	// Open admits a plugin over the backend options.Connect supplies. It needs Sessions.
	Open(ctx context.Context, d plugin.Descriptor, options plugin.Options) (Session, error)
	// OpenProcess is Open with a child process the engine itself starts; options.Connect is unused.
	// It needs Sessions.
	OpenProcess(ctx context.Context, d plugin.Descriptor, launch Launch, options plugin.Options) (Session, error)
	// contains filtered or unexported methods
}

Engine is one implementation of the plugin engine. Only this package implements it.

func Choose

func Choose(name Name, need Feature) (Engine, error)

Choose returns the engine to use. With Auto (or an empty name) it is the best available engine, in the order cgo, c2go, go, that carries every feature in need. With a name it is that engine, and an engine that is not available, or lacks a feature, is an error that wraps plugin.ErrUnsupported: asking for an engine by name never gets another one.

func Engines

func Engines() []Engine

Engines lists every engine, available or not, in the order Choose prefers them: cgo, c2go, go.

func FromEnvironment

func FromEnvironment(need Feature) (Engine, error)

FromEnvironment is Choose with the name taken from EXT_ENGINE: cgo, c2go, go or auto. Unset or empty is auto.

func Get

func Get(name Name) (Engine, error)

Get returns the engine called name, which must be one of CGo, C2Go and Go. It does not check that the engine is available.

type Feature

type Feature uint

Feature is something an engine may or may not carry. An engine that is not available has none.

const (
	// Services is Call: the engine's pure services (descriptor, request, response, frame, manifest,
	// schema and endpoint rules) run by name on bounded JSON. The pure-Go engine has none: its rules
	// are the Go functions of the contract.
	Services Feature = 1 << iota
	// Sessions is Open, OpenProcess and NewInstances.
	Sessions
	// Progress is Session.CallProgress and plugins that declare progress events.
	Progress
	// Reverse is plugin.Options.Reverse and plugins that declare reverse operations.
	Reverse
)

func (Feature) Has

func (f Feature) Has(want Feature) bool

Has reports whether f holds every feature of want.

func (Feature) String

func (f Feature) String() string

type Instances

type Instances[T any] interface {
	Configure(ctx context.Context, key, revision string, config json.RawMessage) error
	Acquire(key string) (*Lease[T], error)
	Remove(key string) error
	Close(ctx context.Context) error
}

Instances binds typed Go resource factories to leases, replacement, capacity and cleanup, as instance.Manager does, on the engine that created it. It satisfies capability.Configurer.

func NewInstances

func NewInstances[T any](e Engine, options instance.Options[T]) (Instances[T], error)

NewInstances creates a manager of at most options.Capacity instances on e. It needs Sessions.

type Launch

type Launch struct {
	Executable  string
	Arguments   []string
	Environment []string
	// Directory is the child's working directory; empty inherits the host's. It must be absolute.
	Directory string
	// StderrBytes bounds the retained stderr; zero retains 4096 bytes.
	StderrBytes int
}

Launch starts a reviewed executable as the plugin's child process, the way an installed package is run. Executable must be the absolute path of a regular file. The host environment is never inherited: Environment entries are added to a scrubbed base of PATH.

type Lease

type Lease[T any] struct {
	Value    T
	Revision string
	// contains filtered or unexported fields
}

Lease holds an instance until Release; Release reports the error of disposing of a retired one.

func (*Lease[T]) Release

func (l *Lease[T]) Release() error

Release returns the lease. Releasing it twice is the underlying manager's error to report.

type Name

type Name string

Name identifies an engine.

const (
	// CGo is the C engine linked through cgo (the ext_cengine build tag and a C library).
	CGo Name = "cgo"
	// C2Go is the C engine translated to Go.
	C2Go Name = "c2go"
	// Go is the pure-Go engine, the oracle.
	Go Name = "go"
)
const Auto Name = "auto"

Auto asks Choose for the best available engine.

type Session

type Session interface {
	// Engine names the engine that runs this session.
	Engine() Name
	Descriptor() plugin.Descriptor
	State() plugin.State
	// Done is closed once the session has been closed or aborted.
	Done() <-chan struct{}
	Call(ctx context.Context, contract plugin.ContractRef, operation string, payload json.RawMessage) (json.RawMessage, error)
	// CallProgress is Call for an operation that declares progress. It needs Progress; an engine
	// without it reports plugin.ErrUnsupported.
	CallProgress(ctx context.Context, contract plugin.ContractRef, operation string, payload json.RawMessage, onProgress func(plugin.Progress), options ...plugin.CallOptions) (json.RawMessage, error)
	// Close drains the session and frees it; Abort stops work and then frees it.
	Close(ctx context.Context) error
	Abort() error
	// Stderr is the retained, bounded and possibly truncated stderr of a session opened with
	// OpenProcess; empty otherwise. Treat it as untrusted text.
	Stderr() string
}

Session is one admitted connection to a plugin, whichever engine runs it.

Jump to

Keyboard shortcuts

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