output

package
v1.0.3 Latest Latest
Warning

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

Go to latest
Published: Jan 9, 2023 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrInvalidFormatType = errors.New("invalid format type")

ErrInvalidFormatType is returned when an unsupported format type is used.

Functions

func EncodeJSON

func EncodeJSON(out io.Writer, obj interface{}) error

EncodeJSON is a helper function to decorate any error message with a bit more context and avoid writing the same code over and over for printers.

func EncodeTable

func EncodeTable(out io.Writer, table *uitable.Table) error

EncodeTable is a helper function to decorate any error message with a bit more context and avoid writing the same code over and over for printers.

func EncodeYAML

func EncodeYAML(out io.Writer, obj interface{}) error

EncodeYAML is a helper function to decorate any error message with a bit more context and avoid writing the same code over and over for printers.

Types

type Format

type Format string

Format is a type for capturing supported output formats.

const (
	JSON  Format = "json"
	YAML  Format = "yaml"
	TABLE Format = "table"
)

func ParseFormat

func ParseFormat(s string) (out Format, err error)

ParseFormat takes a raw string and returns the matching Format. If the format does not exists, ErrInvalidFormatType is returned.

func (Format) String

func (o Format) String() string

String returns the string representation of the Format.

func (Format) Write

func (o Format) Write(w io.Writer, obj interface{}) error

Write the output in the given format to the io.Writer. Unsupported formats will return an error.

type Writer

type Writer interface {
	// WriteTable will write tabular output into the given io.Writer, returning
	// an error if any occur.
	WriteTable(out io.Writer) error
	// WriteJSON will write JSON formatted output into the given io.Writer,
	// returning an error if any occur.
	WriteJSON(out io.Writer) error
	// WriteYAML will write YAML formatted output into the given io.Writer,
	// returning an error if any occur.
	WriteYAML(out io.Writer) error
}

Writer is an interface that any type can implement to write supported formats.

Jump to

Keyboard shortcuts

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