utils

package
v0.0.0-...-3b23420 Latest Latest
Warning

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

Go to latest
Published: Oct 3, 2023 License: GPL-3.0 Imports: 18 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNoCurrentPluginCtx = errors.New("failed creating plugin gRPC client: no current plugin context")
	ErrInvalidPluginCtx   = errors.New("failed creating plugin gRPC client: specified context does not exist")
	ErrNotAPluginCtx      = errors.New("failed creating plugin gRPC client: specified context is not a plugin context")
)

Errors relating to gRPC client creation.

View Source
var (
	ErrNoCurrentServerCtx = errors.New("failed creating server HTTP client: no current server context")
	ErrInvalidServerCtx   = errors.New("failed creating server HTTP client: specified context does not exist")
	ErrNotAServerCtx      = errors.New("failed creating server HTTP client: specified context is not a server context")
)

Errors relating to HTTP client creation.

View Source
var (
	ErrNoOutputMode = errors.New("no output mode set for printer")
	ErrNoRowFunc    = errors.New("table output requires a row function")
)

Printer-specific errors.

View Source
var (
	ErrWSNoCurrentServerCtx = errors.New("failed to create server WebSocket client: no current server context")
	ErrWSInvalidServerCtx   = errors.New("failed to create server WebSocket client: specified context does not exist")
	ErrWSNotAServerCtx      = errors.New("failed to create server WebSocket client: specified context is not a server context")
)

Errors relating to WebSocket client creation.

Functions

func Doc

func Doc(raw string) string

Doc normalizes CLI documentation.

func NewSynseGrpcClient

func NewSynseGrpcClient(ctx, certFile string) (*grpc.ClientConn, synse.V3PluginClient, error)

NewSynseGrpcClient creates a new instance of a Synse gRPC client for communicating with Synse plugins.

func NewSynseHTTPClient

func NewSynseHTTPClient(ctx string, certFile string) (synse.Client, error)

NewSynseHTTPClient creates a new Synse HTTP client for communicating with Synse Server instances.

func NewSynseWebsocketClient

func NewSynseWebsocketClient(ctx string, certFile string) (synse.Client, error)

NewSynseWebsocketClient creates a new Synse WebSocket client for communicating with Synse Server over its WebSocket API. The CLI only uses this client for WebSocket-only features, such as streaming live readings.

func NewTabWriter

func NewTabWriter(out io.Writer) *tabwriter.Writer

NewTabWriter creates a tabwriter with default configurations to align input text into tab-spaced columns.

func NormalizeTags

func NormalizeTags(tags []string) []string

NormalizeTags takes a slice specifying tags which may be comma-separated and produces a slice of tags where each element is an individual tag.

func ObjToYAML

func ObjToYAML(obj interface{}) ([]byte, error)

ObjToYAML converts an object to YAML, first marshalling it to JSON.

Typically, one would be able to use yaml.Marshal, but since the autogenerated gRPC/protobuf code does not include tags for YAML, the "private" XXX_ prefixed fields of the gRPC object are serialized out to YAML. The objects have a JSON tag, so by marshaling to JSON first, we can effectively use the JSON tag as a YAML tag as well.

func StringToTag

func StringToTag(s string) (*synse.V3Tag, error)

StringToTag converts a string representation of a Tag to its corresponding gRPC message.

Types

type Printer

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

Printer defines the printing capabilities for CLI output.

func NewPrinter

func NewPrinter(out io.Writer, useJSON, useYaml, noHeader bool) *Printer

NewPrinter creates a new printer to use for output formatting.

func (*Printer) SetHeader

func (p *Printer) SetHeader(header ...string)

SetHeader sets the column header row for tabular formatting.

func (*Printer) SetIntermediateYaml

func (p *Printer) SetIntermediateYaml()

SetIntermediateYaml configures the printer to marshal to JSON prior to marshalling to YAML. See comment on 'nativeYaml' field for details.

func (*Printer) SetRowFunc

func (p *Printer) SetRowFunc(f func(data interface{}) ([]interface{}, error))

SetRowFunc sets the table row printer function, which specifies which data gets printed in a row of the table.

func (*Printer) SetTransformFunc

func (p *Printer) SetTransformFunc(f func(data map[string]interface{}) error)

SetTransformFunc sets the YAML/JSON data transform function. This is optional and can be used to get data into the proper output format.

func (*Printer) Write

func (p *Printer) Write(data interface{}) error

Write writes the data to the Printer's specified output.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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