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 ¶
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 ¶
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 ¶
FromEnvironment is Choose with the name taken from EXT_ENGINE: cgo, c2go, go or auto. Unset or empty is auto.
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 )
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.
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 ¶
Lease holds an instance until Release; Release reports the error of disposing of a retired one.
type Name ¶
type Name string
Name identifies an engine.
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.