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

engine

package
v0.8.0 Latest Latest
Warning

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

Go to latest
Published: Oct 31, 2026 License: BSD-3-Clause Imports: 11 Imported by: 0

Documentation

Overview

Package engine is what the dashboard needs from a container engine: the calls of an API compatible with the Docker Engine API, as the engine of go-wasmcontainers serves them. The viewmodels depend on the Engine interface only, so they test against a fake as well as against a real engine served in-process.

Endpoints a given engine does not serve (an older engine: volumes, disk usage, the event stream, stats, networks) answer ErrUnsupported, told apart from an ordinary "not found" by the router's own 404 (a plain-text body, not the API's JSON error). The dashboard then says what it needs instead of inventing data.

Index

Constants

This section is empty.

Variables

View Source
var ErrUnsupported = errors.New("not served by this engine")

ErrUnsupported is returned for an endpoint the engine does not serve.

Functions

This section is empty.

Types

type DiskUsage

type DiskUsage = api.SystemDataUsage

DiskUsage is GET /system/df, with the engine's Storage addition.

type Engine

type Engine interface {
	Version(ctx context.Context) (api.SystemVersion, error)
	Containers(ctx context.Context, all bool) ([]api.ContainerSummary, error)
	Images(ctx context.Context) ([]api.ImageSummary, error)
	InspectContainer(ctx context.Context, id string) (json.RawMessage, error)
	InspectImage(ctx context.Context, ref string) (json.RawMessage, error)
	Start(ctx context.Context, id string) error
	Kill(ctx context.Context, id string) error
	// Stop stops a running container and returns once it has exited.
	Stop(ctx context.Context, id string) error
	// Restart stops the container if it runs, then starts it.
	Restart(ctx context.Context, id string) error
	Remove(ctx context.Context, id string, force bool) error
	Create(ctx context.Context, name string, req api.ContainerCreateRequest) (api.ContainerCreateResponse, error)
	Pull(ctx context.Context, ref string, progress func(api.JSONMessage)) error
	RemoveImage(ctx context.Context, ref string, force bool) ([]api.ImageDeleteResponseItem, error)
	// Logs returns the multiplexed log stream (see api.Demux).
	Logs(ctx context.Context, id string, follow bool) (io.ReadCloser, error)
	Volumes(ctx context.Context) ([]Volume, error)
	VolumeCreate(ctx context.Context, o api.VolumeCreateOptions) (Volume, error)
	VolumeInspect(ctx context.Context, name string) (json.RawMessage, error)
	VolumeRemove(ctx context.Context, name string, force bool) error
	VolumesPrune(ctx context.Context, all bool) (api.VolumePruneResponse, error)
	DiskUsage(ctx context.Context) (DiskUsage, error)
	Networks(ctx context.Context) ([]Network, error)
	NetworkCreate(ctx context.Context, o api.NetworkCreateRequest) (api.NetworkCreateResponse, error)
	NetworkInspect(ctx context.Context, ref string) (json.RawMessage, error)
	NetworkRemove(ctx context.Context, ref string) error
	// ExecCreate prepares a process in a running container; ExecStart runs
	// it, sending stdin (read until it ends) and returning its output
	// stream (raw with a terminal); closing the stream hangs up, which
	// kills the process. ExecResize sizes its terminal; ExecInspect says
	// whether it runs and its exit code.
	ExecCreate(ctx context.Context, container string, req api.ExecCreateRequest) (string, error)
	ExecStart(ctx context.Context, id string, req api.ExecStartRequest, stdin io.Reader) (io.ReadCloser, error)
	ExecResize(ctx context.Context, id string, height, width uint16) error
	ExecInspect(ctx context.Context, id string) (api.ExecInspect, error)
	// Events calls fn for each event since the given Unix time (0: from
	// now) until ctx ends or the stream does (the engine cuts off a slow
	// reader: reconnect with since and resynchronise).
	Events(ctx context.Context, since int64, fn func(Event)) error
	// Stats calls fn with one reading, or one a second while stream holds,
	// until ctx ends or the stream does.
	Stats(ctx context.Context, id string, stream bool, fn func(Stats)) error
}

Engine is the API the dashboard drives.

type Event

type Event = api.EventMessage

Event is one message of GET /events.

type HTTP

type HTTP struct {
	*api.Client
	// contains filtered or unexported fields
}

HTTP is the Engine over an HTTP client: a unix socket, or the bridge the browser uses.

func New

func New(hc *http.Client, base string) *HTTP

New speaks to the engine at base (e.g. "http://engine") through hc.

func (*HTTP) DiskUsage

func (h *HTTP) DiskUsage(ctx context.Context) (DiskUsage, error)

DiskUsage reports storage use.

func (*HTTP) Events

func (h *HTTP) Events(ctx context.Context, since int64, fn func(Event)) error

Events streams events.

func (*HTTP) InspectContainer

func (h *HTTP) InspectContainer(ctx context.Context, id string) (json.RawMessage, error)

InspectContainer inspects a container.

func (*HTTP) InspectImage

func (h *HTTP) InspectImage(ctx context.Context, ref string) (json.RawMessage, error)

InspectImage inspects an image.

func (*HTTP) Networks added in v0.5.0

func (h *HTTP) Networks(ctx context.Context) ([]Network, error)

Networks lists networks (ErrUnsupported from an engine without them).

func (*HTTP) Stats added in v0.3.0

func (h *HTTP) Stats(ctx context.Context, id string, stream bool, fn func(Stats)) error

Stats reads a container's stats.

func (*HTTP) Volumes

func (h *HTTP) Volumes(ctx context.Context) ([]Volume, error)

Volumes lists volumes.

type Network added in v0.5.0

type Network = api.Network

Network is one entry of GET /networks.

type Stats added in v0.3.0

type Stats = api.ContainerStats

Stats is one reading of GET /containers/{id}/stats.

type Volume

type Volume = api.Volume

Volume is one entry of GET /volumes.

Jump to

Keyboard shortcuts

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