output

package
v1.0.106 Latest Latest
Warning

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

Go to latest
Published: Apr 5, 2024 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package output formats and prints the response on standard output.

- Supports JSON and text output - Provides mechanism to transform output using JMESPath queries

Index

Constants

View Source
const FieldSeparator = "\t"
View Source
const ObjectSeparator = "\n"

Variables

This section is empty.

Functions

This section is empty.

Types

type DefaultTransformer

type DefaultTransformer struct {
}

The DefaultTransformer simply passes through the output from the output writer. No transformation is performed.

func NewDefaultTransformer

func NewDefaultTransformer() *DefaultTransformer

func (DefaultTransformer) Execute

func (t DefaultTransformer) Execute(data interface{}) (interface{}, error)

type JmesPathTransformer

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

The JmesPathTransformer uses the JMESPath query language to transform the executor output.

It is used when the --query parameter is provided. Example: --query "id"

{
  "id": "521b4edc-ad6f-4301-909e-f96a401e1fed",
}

=> "521b4edc-ad6f-4301-909e-f96a401e1fed"

See https://jmespath.org for more information.

func NewJmesPathTransformer

func NewJmesPathTransformer(query string) *JmesPathTransformer

func (JmesPathTransformer) Execute

func (t JmesPathTransformer) Execute(data interface{}) (interface{}, error)

type JsonOutputWriter

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

The JsonOutputWriter formats the CLI output as prettified json.

It is used by default or when the --output json parameter is provided. Example:

{
 "foo": "bar"
}

func NewJsonOutputWriter

func NewJsonOutputWriter(output io.Writer, transformer Transformer) *JsonOutputWriter

func (JsonOutputWriter) WriteResponse

func (w JsonOutputWriter) WriteResponse(response ResponseInfo) error

type MemoryOutputWriter

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

The MemoryOutputWriter keeps the response in memory so it can read multiple times.

func NewMemoryOutputWriter

func NewMemoryOutputWriter() *MemoryOutputWriter

func (MemoryOutputWriter) Response

func (w MemoryOutputWriter) Response() ResponseInfo

func (*MemoryOutputWriter) WriteResponse

func (w *MemoryOutputWriter) WriteResponse(response ResponseInfo) error

type OutputWriter

type OutputWriter interface {
	WriteResponse(response ResponseInfo) error
}

The OutputWriter is used to print the executor result on standard output.

type ResponseInfo

type ResponseInfo struct {
	StatusCode int
	Status     string
	Protocol   string
	Header     map[string][]string
	Body       io.Reader
}

ResponseInfo contains the information used by the output writer to print the executor result on standard output.

func NewResponseInfo

func NewResponseInfo(statusCode int, status string, protocol string, header map[string][]string, body io.Reader) *ResponseInfo

type TextOutputWriter

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

The TextOutputWriter formats the CLI output as text meaning fields are separated by tabs and multiple elements by newline.

It is used when the --output text parameter is provided. Example: foo1 bar1 foo2 bar2

func NewTextOutputWriter

func NewTextOutputWriter(output io.Writer, transformer Transformer) *TextOutputWriter

func (TextOutputWriter) WriteResponse

func (w TextOutputWriter) WriteResponse(response ResponseInfo) error

type Transformer

type Transformer interface {
	Execute(data interface{}) (interface{}, error)
}

The Transformer interface can be implemented to provide a converter which transforms the CLI output into a different structure.

Jump to

Keyboard shortcuts

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