jsonstream

package
v0.0.0-...-bc5839e Latest Latest
Warning

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

Go to latest
Published: Sep 7, 2020 License: Apache-2.0 Imports: 10 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

Index

Constants

View Source
const (
	// PullStatusDownloading represents downloading status.
	PullStatusDownloading = "downloading"
	// PullStatusWaiting represents waiting status.
	PullStatusWaiting = "waiting"
	// PullStatusResolving represents resolving status.
	PullStatusResolving = "resolving"
	// PullStatusResolved represents resolved status.
	PullStatusResolved = "resolved"
	// PullStatusExists represents exist status.
	PullStatusExists = "exists"
	// PullStatusDone represents done status.
	PullStatusDone = "done"

	// PushStatusUploading represents uploading status.
	PushStatusUploading = "uploading"
)

Variables

This section is empty.

Functions

func ProcessStatus

func ProcessStatus(short bool, msg JSONMessage) string

ProcessStatus returns the status of download or upload image

NOTE: if the stdout is not terminal, it should only show the reference and status without progress bar.

func PushProcess

func PushProcess(ctx context.Context, ongoing *PushJobs, stream *JSONStream)

PushProcess translates upload progress to json stream

Types

type Formater

type Formater interface {
	// BeginWrite write some data at the stream beginning.
	BeginWrite() ([]byte, error)

	// EndWrite write some data at the stream ending.
	EndWrite() ([]byte, error)

	// Write write a object be serialized.
	Write(o interface{}) ([]byte, error)
}

Formater define the data's format via stream transfer.

type JSONError

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

JSONError wraps a concrete Code and Message as error.

func (*JSONError) Error

func (e *JSONError) Error() string

Error implement the error interface.

type JSONMessage

type JSONMessage struct {
	ID           string          `json:"id,omitempty"`
	Status       string          `json:"status,omitempty"`
	Detail       *ProgressDetail `json:"progressDetail,omitempty"`
	Error        *JSONError      `json:"errorDetail,omitempty"`
	ErrorMessage string          `json:"error,omitempty"`

	StartedAt time.Time `json:"started_at,omitempty"`
	UpdatedAt time.Time `json:"updated_at,omitempty"`
}

JSONMessage defines a message struct for jsonstream. It describes id, status, progress detail, started and updated.

type JSONStream

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

JSONStream represents a stream transfer, the data be encoded with json.

func New

func New(out io.Writer, f Formater) *JSONStream

New creates a 'JSONStream' instance and use a goroutine to recv/send data.

func (*JSONStream) Close

func (s *JSONStream) Close() error

Close closes the stream transfer.

func (*JSONStream) Wait

func (s *JSONStream) Wait()

Wait waits the stream to finish.

func (*JSONStream) WriteObject

func (s *JSONStream) WriteObject(obj interface{}) error

WriteObject writes a object to client via stream tranfer.

type ProgressDetail

type ProgressDetail struct {
	Current int64 `json:"current"`
	Total   int64 `json:"total"`
}

ProgressDetail represents the status.

type PushJobs

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

PushJobs defines a job in upload progress

func NewPushJobs

func NewPushJobs(tracker docker.StatusTracker) *PushJobs

NewPushJobs news a PushJobs

func (*PushJobs) Add

func (j *PushJobs) Add(ref string)

Add adds a ref in upload job

func (*PushJobs) Status

func (j *PushJobs) Status() []JSONMessage

Status gets PushJobs statuses

Jump to

Keyboard shortcuts

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