formatters

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Jun 28, 2023 License: MIT Imports: 11 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ComputeOutputFilename added in v0.2.58

func ComputeOutputFilename(
	outputFile string,
	outputFileTemplate string,
	row types.Row,
	index int,
) (string, error)

func StartFormatIntoChannel added in v0.2.82

func StartFormatIntoChannel[T interface{ ~string }](
	ctx context.Context,
	table *types.Table,
	formatter TableOutputFormatter,
) <-chan T

StartFormatIntoChannel outputs the data from an TableOutputFormatter into a channel. This is useful to render a table into a stream, for example when rendering larger outputs into HTML when serving.

func StartStreamRows added in v0.3.0

func StartStreamRows[T interface{ ~string }](
	ctx context.Context,
	formatter RowOutputFormatter,
) (chan<- types.Row, <-chan T)

StartStreamRows starts a background goroutine that returns two channels. The first channel is used to send rows to the background goroutine, the second channel is used to receive the formatted output.

This background goroutine will close the output channel when it is done.

func StreamRows added in v0.3.0

func StreamRows(
	ctx context.Context,
	formatter RowOutputFormatter,
	inputChannel <-chan types.Row,
	outputChannel <-chan string,
) error

Types

type RowOutputFormatter added in v0.3.0

type RowOutputFormatter interface {
	RegisterMiddlewares(mw *middlewares.Processor) error
	Output(ctx context.Context, row types.Row, w io.Writer) error
	ContentType() string
}

type TableOutputFormatter

type TableOutputFormatter interface {
	// RegisterMiddlewares allows individual OutputFormatters to register middlewares that might be
	// necessary for them to do the proper output. For example, table and excel output require
	// flattening the row objects before output.
	//
	// TODO(manuel, 2023-06-28) We could add the indication if this output formatter can stream here
	// Not all output formatters should have to take a full table, but could instead output a single row
	RegisterMiddlewares(mw *middlewares.Processor) error

	Output(ctx context.Context, table *types.Table, w io.Writer) error
	ContentType() string
}

TableOutputFormatter is an output formatter that requires an entire table to be computed up front before it can be output.

NOTE(manuel, 2023-06-28) Since this is actually the first type of Formatter that was implemented, it is the current de facto standard. RowOutputFormatter has been added later and is thus not in wide spread use.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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