Documentation ¶
Overview ¶
Package yaff yet another flexible formatter.
Example ¶
package main import ( "bytes" "fmt" "github.com/nehemming/yaff" "github.com/nehemming/yaff/textformatter" ) type dataRow struct { StringVal string IntVal int FloatVal float64 BoolVal bool OnlyTrueVal bool `tabular:",trueonly"` hidden int //nolint:structcheck Embedded embeddedData } type embeddedData struct { innerStr string IntTwo int } func main() { // Get the text formatter formatter, err := yaff.Formatters().GetFormatter(textformatter.Text) if err != nil { fmt.Println(err) return } options := textformatter.NewOptions() // Output in grid style options.Style = textformatter.Grid // Generate some output, using io writer interface of Buffer var buf bytes.Buffer err = formatter.Format(&buf, options, []dataRow{ { StringVal: "Hello", IntVal: 10, FloatVal: 9.8, BoolVal: true, OnlyTrueVal: true, hidden: 99, Embedded: embeddedData{innerStr: "hidden", IntTwo: 2}, }, { StringVal: "There", IntVal: 20, FloatVal: 3.14, BoolVal: false, OnlyTrueVal: false, hidden: 99, Embedded: embeddedData{innerStr: "hidden2", IntTwo: 2}, }, }) if err != nil { fmt.Println(err) } else { fmt.Println(buf.String()) } } func main() { main() }
Output: +-----------+--------+----------+---------+-------------+--------+ | StringVal | IntVal | FloatVal | BoolVal | OnlyTrueVal | IntTwo | +-----------+--------+----------+---------+-------------+--------+ | Hello | 10 | 9.8 | true | true | 2 | +-----------+--------+----------+---------+-------------+--------+ | There | 20 | 3.14 | false | | 2 | +-----------+--------+----------+---------+-------------+--------+
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type FormatOptions ¶
type FormatOptions interface{}
FormatOptions options controlling formatting, every formatter can implement its own options.
type Formatter ¶
type Formatter interface { // Format formats the supplied input data using the format options with output to the writer. Format(writer io.Writer, options FormatOptions, data ...interface{}) error }
Formatter supports writing formated data to an writer.
type NewFormatter ¶
NewFormatter function type to create a new formatter. Each formatter type registered will provide an implementation to creeate an instance of an associated formatter.
type Registry ¶
type Registry interface { // Register adds or updates an available format. // The NewFormatter factory is used to create an // instance oif the registered formatter. Register(format Format, factory NewFormatter) // GetFormatter returns the formatter supporting the format or an error if no formatter can be found. GetFormatter(format Format) (Formatter, error) // Formats returns a slice of supported formats. Formats() []Format }
Registry holds a list of available formatters. It is possible to create multiple formatters, but by default the default shared yaff.Formatters registry can be used Registry implementors must be threadsafe across all calls.
Directories ¶
Path | Synopsis |
---|---|
Package cliflags allows an application to bind parameters to control outputt formats
|
Package cliflags allows an application to bind parameters to control outputt formats |
langpack
Package langpack for yaff cli flags.
|
Package langpack for yaff cli flags. |
Package csvformatter is the yaff JSON formatter.
|
Package csvformatter is the yaff JSON formatter. |
Package jsonformatter is the yaff JSON formatter.
|
Package jsonformatter is the yaff JSON formatter. |
Package langpack for yaff.
|
Package langpack for yaff. |
Package templateformatter is the yaff Template formatter.
|
Package templateformatter is the yaff Template formatter. |
Package textformatter is the yaff Text formatter.
|
Package textformatter is the yaff Text formatter. |
Package yamlformatter is the yaff YAML formatter.
|
Package yamlformatter is the yaff YAML formatter. |
Click to show internal directories.
Click to hide internal directories.