multiwriter

package module
v0.0.0-...-07eb46d Latest Latest
Warning

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

Go to latest
Published: Nov 30, 2020 License: MIT Imports: 7 Imported by: 0

README

go-multiwriter

Golang library for writing structured data to various output formats

Documentation

Index

Constants

View Source
const (

	// CSVFormat sets output format to comma-separated values
	CSVFormat = "csv"
	// TableFormat sets output format to an ASCII table
	TableFormat = "table"
	// TextFormat sets the output format to a fmt-renderd text string
	TextFormat = "text"
)

Variables

AllFormats contains all the formats supported

Functions

This section is empty.

Types

type BasicFormatter

type BasicFormatter struct {
	FmtString string
}

BasicFormatter uses fmt.Sprintf to format based on a static format string

func (BasicFormatter) Format

func (bf BasicFormatter) Format(value string) string

Format formats value by applying format with fmt.Sprintf

type Formatter

type Formatter interface {
	// Format formats as source string into a new string
	Format(string) string
}

Formatter is a dumb way to inject custom formatting logic for column data. This can be useful for outputting prefix/suffixes or other basic translations

type FuncFormatter

type FuncFormatter func(string) string

FuncFormatter wraps a user-defined function to apply formatting

func (FuncFormatter) Format

func (ff FuncFormatter) Format(value string) string

Format formats the value by calling the external function

type Option

type Option func(*Writer)

Option modifies default options of the Writer

func WithFormatter

func WithFormatter(column string, f Formatter) Option

WithFormatter sets the text formatting for the column

func WithSize

func WithSize(size int) Option

WithSize modifies the size of the internal buffer

type Writer

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

Writer writes structured data to an internal buffer and outputs it as a given format when flushed

func New

func New(writer io.Writer, columns []string, format string, opts ...Option) *Writer

New returns a new Writer for writing. Format should be one of AllFormats. The size value determines how big the internal buffer should be. When the buffer fills, the writer automatically flushes it.

func (*Writer) Error

func (w *Writer) Error() error

Error returns whether there was an error writing.

func (*Writer) Flush

func (w *Writer) Flush()

Flush flushes all records from the internal buffer to its output writer

func (*Writer) Write

func (w *Writer) Write(record []string) error

Write writes the record to the internal buffer

Directories

Path Synopsis
example
formatters
package main is an example program to demonstrate how to use custom column formatters.
package main is an example program to demonstrate how to use custom column formatters.

Jump to

Keyboard shortcuts

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