driver

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Dec 2, 2026 License: MIT Imports: 4 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 driver chooses how a library of lib/ runs in a program. It knows no library: a library's Go package lists its own drivers and asks Choose for one.

A driver is one way of reaching the library's code:

cgo     the C library linked through cgo, fixed when the program is built
c2go    the C library translated to Go by ccgo, fixed when the program is built
purego  the C library as a shared library loaded when the program runs (cengine/library)
go      a legacy pure-Go implementation, where the library still provides one

Choose prefers them in that order. A program names one, or asks for the best available one with Auto; FromEnvironment reads the name from EXT_ENGINE. Asking for a driver by name never gets another one: a name that cannot be served is an error.

Index

Constants

View Source
const Environment = "EXT_ENGINE"

Environment is the variable FromEnvironment reads: a driver name, or auto (the default).

Variables

View Source
var (
	// ErrUnknown is a name that is not a driver.
	ErrUnknown = errors.New("unknown driver")
	// ErrUnavailable is a driver this build or this machine cannot serve.
	ErrUnavailable = errors.New("driver unavailable")
)

Functions

func Choose

func Choose[D Driver](drivers []D, want Name, fits func(D) error) (D, error)

Choose returns the driver called want from drivers, or with Auto (or an empty name) the first available one, in Order, for which fits returns nil. fits says why an available driver does not serve the caller, such as a missing feature; nil fits accepts every available driver. A named driver that is missing from drivers, unavailable or rejected by fits is an error, never another driver.

Types

type Driver

type Driver interface {
	Name() Name
	// Available reports whether this build and this machine hold the driver.
	Available() bool
}

Driver is what a library's Go package lists for each way it can run.

type Name

type Name string

Name identifies a driver.

const (
	// CGo is the C library linked through cgo.
	CGo Name = "cgo"
	// C2Go is the C library translated to Go.
	C2Go Name = "c2go"
	// PureGo is the C library loaded at run time as a shared library.
	PureGo Name = "purego"
	// Go is the library's pure-Go implementation.
	Go Name = "go"
)
const Auto Name = "auto"

Auto asks Choose for the best available driver.

func FromEnvironment

func FromEnvironment() (Name, error)

FromEnvironment is Parse of EXT_ENGINE.

func Order

func Order() []Name

Order lists every driver in the order Choose prefers them.

func Parse

func Parse(s string) (Name, error)

Parse reads a driver name. Empty is Auto; any other name that is not a driver is ErrUnknown.

Jump to

Keyboard shortcuts

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