printer

package
v0.3.1 Latest Latest
Warning

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

Go to latest
Published: Sep 11, 2019 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Flatten added in v0.1.3

func Flatten(obj map[string]interface{}, t []TemplateItem) []interface{}

Flatten an object using the template.

func GetLabels added in v0.1.3

func GetLabels(items []TemplateItem) []interface{}

Converts TemplateItems to an array of label.

func GetValue added in v0.1.3

func GetValue(m map[string]interface{}, path string) (error, interface{})

Get a value from the map by a path separated by dots. Example: gsInfo.gsLat

Types

type CSVPrinter

type CSVPrinter struct {
	// Options of CSV format.
	Options CSVPrinterOptions
	// contains filtered or unexported fields
}

A Printer which output values as a CSV format.

func NewCSVPrinter

func NewCSVPrinter(o CSVPrinterOptions) *CSVPrinter

Create a new CSVPrinter

func (*CSVPrinter) Flush

func (p *CSVPrinter) Flush()

Flush data in the buffer. This function must be called to output all data.

func (*CSVPrinter) Write

func (p *CSVPrinter) Write(r []interface{})

Format and write fields represented as an array.

func (*CSVPrinter) WriteHeader added in v0.1.3

func (p *CSVPrinter) WriteHeader(t []TemplateItem)

Write a header.

func (*CSVPrinter) WriteWithTemplate added in v0.1.3

func (p *CSVPrinter) WriteWithTemplate(r []map[string]interface{}, t []TemplateItem)

Write fields with the template.

type CSVPrinterOptions

type CSVPrinterOptions struct {
	Out io.Writer

	// A string that represents end of line.
	CRLF string
	// Date format used to convert time.Time to string.
	DateFormat string
	// CSVPrinter quote the string value if QuoteString is true.
	QuoteString bool
	// Separator between columns.
	Separator string
}

A set of options used for CSV format.

func NewCSVPrinterOptions

func NewCSVPrinterOptions(output io.Writer) CSVPrinterOptions

Create a CSVPrinterOptions with default values set.

type JSONPrinter added in v0.1.3

type JSONPrinter struct {
	// Options of JSON format.
	Options JSONPrinterOptions
	// contains filtered or unexported fields
}

func NewJSONPrinter added in v0.1.3

func NewJSONPrinter(o JSONPrinterOptions) *JSONPrinter

func (*JSONPrinter) Flush added in v0.1.3

func (p *JSONPrinter) Flush()

func (*JSONPrinter) Write added in v0.1.3

func (p *JSONPrinter) Write(r []interface{})

func (*JSONPrinter) WriteHeader added in v0.1.3

func (p *JSONPrinter) WriteHeader(t []TemplateItem)

Write a header

func (*JSONPrinter) WriteWithTemplate added in v0.1.3

func (p *JSONPrinter) WriteWithTemplate(r []map[string]interface{}, t []TemplateItem)

Write fields with the template.

type JSONPrinterOptions added in v0.1.3

type JSONPrinterOptions struct {
	Out io.Writer

	Indent string
}

func NewJSONPrinterOptions added in v0.1.3

func NewJSONPrinterOptions(output io.Writer) JSONPrinterOptions

type Printer

type Printer interface {
	// Write buffered data to the underlying io.Writer.
	Flush()
	// Write an object represented as an array.
	Write(r []interface{})
	// Write a header.
	WriteHeader(t []TemplateItem)
	// Write an object with a template.
	WriteWithTemplate(r []map[string]interface{}, t []TemplateItem)
}

Printer is the interface to output values.

type TemplateItem added in v0.1.3

type TemplateItem struct {
	Label string
	Path  string
}

type WidePrinter

type WidePrinter struct {
	Options WidePrinterOptions
	// contains filtered or unexported fields
}

func NewWidePrinter

func NewWidePrinter(o WidePrinterOptions) *WidePrinter

Create a new WidePrinter.

func (*WidePrinter) Flush

func (p *WidePrinter) Flush()

Flush data in the buffer. This function must be called to output all data.

func (*WidePrinter) Write

func (p *WidePrinter) Write(r []interface{})

Format and write fields represented as an array.

func (*WidePrinter) WriteHeader added in v0.1.3

func (p *WidePrinter) WriteHeader(t []TemplateItem)

Write a header.

func (*WidePrinter) WriteWithTemplate added in v0.1.3

func (p *WidePrinter) WriteWithTemplate(r []map[string]interface{}, t []TemplateItem)

Write fields with the template.

type WidePrinterOptions

type WidePrinterOptions struct {
	Out io.Writer

	CRLF       string
	DateFormat string
	Flags      uint
	MinWidth   int
	TabWidth   int
	Padding    int
	PadChar    byte
}

func NewWidePrinterOptions

func NewWidePrinterOptions(output io.Writer) WidePrinterOptions

Create a WidePrinterOptions with default values set.

Jump to

Keyboard shortcuts

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