output

package
v0.0.0-...-92a1719 Latest Latest
Warning

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

Go to latest
Published: Dec 18, 2024 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Overview

Package output provides utilities for outputting data in different formats such as JSON, YAML, and text. It includes functionality for creating an output client that writes data to an io.Writer based on a specified format.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BasicOutput

type BasicOutput struct {
	Vals map[string]interface{}
}

BasicOutput is a simple struct that contains a name field that can be marshaled into different formats

This struct is used to demonstrate how to implement the Outputable interface and can be embedded into other structs

func (*BasicOutput) EncodeJSON

func (b *BasicOutput) EncodeJSON() ([]byte, error)

EncodeJSON marshals the BasicOutput object into a json format

func (*BasicOutput) EncodeText

func (b *BasicOutput) EncodeText() ([]byte, error)

EncodeText marshals the BasicOutput object into a human readable format by calling the String method

func (*BasicOutput) EncodeYAML

func (b *BasicOutput) EncodeYAML() ([]byte, error)

MashalYaml marshals the BasicOutput object into a yaml format

func (*BasicOutput) String

func (b *BasicOutput) String() string

String returns the name of the BasicOutput object in a human readable format

type Client

type Client interface {
	Output(data Outputable) error
}

Client is the interface that wraps the basic Output method.

Output takes an Outputable object and writes it to an io.Writer based on a specified format.

func NewOutputClient

func NewOutputClient(format Format, streams genericIOOptions.IOStreams) Client

NewOutputClient creates a new output client based on the specified format and io streams.

format: The desired output format (JSON, YAML, TEXT) streams: The generic I/O streams for input/output operations.

type ClientGetter

type ClientGetter struct{}

ClientGetter is an interface for getting an BB output client.

func (*ClientGetter) GetClient

func (clientGetter *ClientGetter) GetClient(format Format, streams genericclioptions.IOStreams) Client

GetClient returns a new log client.

type Format

type Format string

Format defines constants for supported output formats.

const (
	JSON Format = "json"
	TEXT Format = "text"
	YAML Format = "yaml"
)

type Outputable

type Outputable interface {
	// MashalYaml marshals the object into a yaml format
	EncodeYAML() ([]byte, error)
	// EncodeJSON marshals the object into a json format
	EncodeJSON() ([]byte, error)
	// EncodeText marshals the object into a human readable format
	EncodeText() ([]byte, error)
}

Outputable interface is used to define the methods that an object must implement in order to be able to be marshaled into different formats

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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