jsontabwriter

package
v6.7.6 Latest Latest
Warning

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

Go to latest
Published: Apr 12, 2024 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const (

	// JSONFormat defines the legacy JSON format. It will eventually be removed and fully replaced by APIFormat
	// (in terms of behavior, the name will be kept)
	JSONFormat = "json"
	// TextFormat defines a human-readable format.
	TextFormat = "text"
	// APIFormat defines the API matching JSON format. This will be removed once its behavior will be moved to JSONFormat
	APIFormat = "api-json"
)

Variables

This section is empty.

Functions

func GenerateLogOutput

func GenerateLogOutput(format string, a ...interface{}) string

GenerateLogOutput is similar to fmt.Sprintf, but it will return the string in either JSON or text format.

func GenerateOutput

func GenerateOutput(
	columnPathMappingPrefix string, columnPathMapping map[string]string, sourceData interface{}, cols []string,
) (string, error)

GenerateOutput converts and formats source data into printable output.

columnPathMappingPrefix: Points to a specific location in the JSON or struct object from where extraction should begin. If left empty, it will start from the root of the object.

columnPathMapping: A map where each key represents the desired column name in the output table, and each value represents a JSON path to extract the data within the given JSON or struct.

sourceData: JSON or struct from which data should be extracted, converted and formatted.

cols: The columns that need to be printed

Returns a ready-to-print string, which has the source data in either human-readable/table or JSON format

TODO: remove cols as function parameter once --cols flag fix is ready

func GenerateOutputPreconverted

func GenerateOutputPreconverted(
	rawSourceData interface{}, convertedSourceData []map[string]interface{}, cols []string,
) (string, error)

GenerateOutputPreconverted is just like GenerateOutput, but it assumes that the source data has already been converted from JSON to table format. It is recommended when certain table columns cannot be automatically extracted from source data and require to be manually populated.

rawSourceData: JSON or struct which will be used for JSON formatted output

convertedSourceData: Table which will be used for human-readable output

cols: The columns that need to be printed

Returns a ready-to-print string, which has the source data in either human-readable/table or JSON format

func GenerateRawOutput

func GenerateRawOutput(a interface{}) string

GenerateRawOutput takes a generic variable and converts it to plain JSON or human-readable output without additional formatting fluff.

func GenerateVerboseOutput

func GenerateVerboseOutput(format string, a ...interface{}) string

Types

This section is empty.

Jump to

Keyboard shortcuts

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