jsonmessage

package
v24.0.2 Latest Latest
Warning

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

Go to latest
Published: May 25, 2023 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
const RFC3339NanoFixed = "2006-01-02T15:04:05.000000000Z07:00"

RFC3339NanoFixed is time.RFC3339Nano with nanoseconds padded using zeros to ensure the formatted time isalways the same number of characters.

Variables

This section is empty.

Functions

func DisplayJSONMessagesStream

func DisplayJSONMessagesStream(in io.Reader, out io.Writer, terminalFd uintptr, isTerminal bool, auxCallback func(JSONMessage)) error

DisplayJSONMessagesStream reads a JSON message stream from in, and writes each JSONMessage to out. It returns an error if an invalid JSONMessage is received, or if a JSONMessage containers a non-zero [JSONMessage.Error].

Presentation of the JSONMessage depends on whether a terminal is attached, and on the terminal width. Progress bars (JSONProgress) are suppressed on narrower terminals (< 110 characters).

  • isTerminal describes if out is a terminal, in which case it prints a newline ("\n") at the end of each line and moves the cursor while displaying.
  • terminalFd is the fd of the current terminal (if any), and used to get the terminal width.
  • auxCallback allows handling the [JSONMessage.Aux] field. It is called if a JSONMessage contains an Aux field, in which case DisplayJSONMessagesStream does not present the JSONMessage.

func DisplayJSONMessagesToStream

func DisplayJSONMessagesToStream(in io.Reader, stream Stream, auxCallback func(JSONMessage)) error

DisplayJSONMessagesToStream prints json messages to the output Stream. It is used by the Docker CLI to print JSONMessage streams.

Types

type JSONError

type JSONError struct {
	Code    int    `json:"code,omitempty"`
	Message string `json:"message,omitempty"`
}

JSONError wraps a concrete Code and Message, Code is an integer error code, Message is the error message.

func (*JSONError) Error

func (e *JSONError) Error() string

type JSONMessage

type JSONMessage struct {
	Stream          string        `json:"stream,omitempty"`
	Status          string        `json:"status,omitempty"`
	Progress        *JSONProgress `json:"progressDetail,omitempty"`
	ProgressMessage string        `json:"progress,omitempty"` // deprecated
	ID              string        `json:"id,omitempty"`
	From            string        `json:"from,omitempty"`
	Time            int64         `json:"time,omitempty"`
	TimeNano        int64         `json:"timeNano,omitempty"`
	Error           *JSONError    `json:"errorDetail,omitempty"`
	ErrorMessage    string        `json:"error,omitempty"` // deprecated
	// Aux contains out-of-band data, such as digests for push signing and image id after building.
	Aux *json.RawMessage `json:"aux,omitempty"`
}

JSONMessage defines a message struct. It describes the created time, where it from, status, ID of the message. It's used for docker events.

func (*JSONMessage) Display

func (jm *JSONMessage) Display(out io.Writer, isTerminal bool) error

Display prints the JSONMessage to out. If isTerminal is true, it erases the entire current line when displaying the progressbar. It returns an error if the [JSONMessage.Error] field is non-nil.

type JSONProgress

type JSONProgress struct {
	// Current is the current status and value of the progress made towards Total.
	Current int64 `json:"current,omitempty"`
	// Total is the end value describing when we made 100% progress for an operation.
	Total int64 `json:"total,omitempty"`
	// Start is the initial value for the operation.
	Start int64 `json:"start,omitempty"`
	// HideCounts. if true, hides the progress count indicator (xB/yB).
	HideCounts bool `json:"hidecounts,omitempty"`
	// Units is the unit to print for progress. It defaults to "bytes" if empty.
	Units string `json:"units,omitempty"`
	// contains filtered or unexported fields
}

JSONProgress describes a progress message in a JSON stream.

func (*JSONProgress) String

func (p *JSONProgress) String() string

type Stream

type Stream interface {
	io.Writer
	FD() uintptr
	IsTerminal() bool
}

Stream is an io.Writer for output with utilities to get the output's file descriptor and to detect wether it's a terminal.

it is subset of the streams.Out type in https://pkg.go.dev/github.com/docker/cli@v20.10.17+incompatible/cli/streams#Out

Jump to

Keyboard shortcuts

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