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

progress

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Oct 26, 2026 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Overview

Package progress is how long operations report what they do. The code that does the work emits events and never prints; whoever drives it renders them.

The installer runs in a container of its own: it writes its events as JSON lines, and the runtime reads them back from its output with Writer.

Index

Constants

View Source
const (
	Variable   = "NEMO_PROGRESS"
	FormatJSON = "json"
)

Variable is the environment variable by which the runtime asks the installer for its events as JSON lines, setting it to FormatJSON.

View Source
const (
	// Installation is an action on an installation, its Message the action.
	Installation = "installation"
	// Images is the loading of the images into the target's daemon.
	Images = "images"
	// Output is a line the installer printed that is not an event.
	Output = "output"
)

Groups of the events about something else than the objects an orchestrator creates.

Variables

This section is empty.

Functions

This section is empty.

Types

type Event

type Event struct {
	// Installation is the installation the event is about, stack/name: the
	// runtime sets it on the events of the installer it runs.
	Installation string `json:"installation,omitempty"`
	Group        string `json:"group"`
	Item         string `json:"item,omitempty"`
	State        State  `json:"state"`
	Current      int64  `json:"current,omitempty"`
	Total        int64  `json:"total,omitempty"`
	Message      string `json:"message,omitempty"`
}

Event is one step of an operation, about one item of a group: a network, a volume, a service. Readers ignore the fields they do not know, so fields are only ever added.

type Sink

type Sink interface {
	Emit(Event)
}

Sink receives events.

var Discard Sink = SinkFunc(func(Event) {})

Discard drops every event.

func About

func About(sink Sink, installation string) Sink

About returns the sink that sets the installation of each event.

func Installer

func Installer(format string, stdout, stderr io.Writer) (Sink, io.Writer)

Installer returns where an installer writes, as format, Variable's value, asks: the sink of its events and the writer of the error that ends it. For FormatJSON both are stdout, so that Writer reads the error after the events, in order; otherwise the events are text on stdout and the error goes to stderr.

func JSON

func JSON(output io.Writer) Sink

JSON writes each event as a line of JSON, for Writer to read back.

func Text

func Text(output io.Writer) Sink

Text writes each event as a line of text, for whoever runs the installer without nemo's runtime, Porter for one.

type SinkFunc

type SinkFunc func(Event)

SinkFunc is a Sink made of a function.

func (SinkFunc) Emit

func (sink SinkFunc) Emit(event Event)

type State

type State string

State is where an item stands.

const (
	Pending State = "pending"
	Working State = "working"
	Done    State = "done"
	Warning State = "warning"
	Error   State = "error"
)

type Writer

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

Writer reads what an installer prints, its events as JSON lines, and emits them about its installation; any other line is an Output event.

func NewWriter

func NewWriter(sink Sink, installation string) *Writer

NewWriter returns the writer of the installation's output.

func (*Writer) Close

func (writer *Writer) Close() error

Close emits the last line, when it did not end.

func (*Writer) Write

func (writer *Writer) Write(data []byte) (int, error)

Jump to

Keyboard shortcuts

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