# README
Formatter
This stable version.
Description
Tabular data formatting package.
Supports formats
- table text/template
- text/template
- raw
- pretty
- json
- yaml
Installation
$ go get github.com/mantyr/formatter
Format examples
table {{.ID}}\t{{.Name}}
- Aligns columns and adds a header{{.ID}}\t{{.Name}}
- Displays to a string according to the formatraw
- Displays the object line by line (field: value)json
- Displays in json formatyaml
- Displays in yaml format
Example
package main
import (
"github.com/mantyr/formatter"
)
func main() {
err = Print(...)
if err != nil {
panic(err)
}
}
func Print(items []interface{}) error {
format := formatter.Format("table {{.ID}}\t{{.Name}}\t")
header := formatter.Header(map[string]string{
"ID": "Identifier",
"Name": "Name",
})
f, err := formatter.New(os.Stdout)
if err != nil {
return err
}
defer f.Flush()
err = f.SetFormat(format)
if err != nil {
return err
}
err = f.SetHeader(header)
if err != nil {
return err
}
for _, item := range items {
err = f.Write(item)
if err != nil {
return err
}
}
return nil
}
Author
# Functions
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
PadWithSpace adds whitespace to the input if the input is non-empty.
TruncateWithLength truncates the source string up to the length provided by the input.
# Constants
Format keys used to specify certain kinds of output formats.
Format keys used to specify certain kinds of output formats.
Format keys used to specify certain kinds of output formats.
Format keys used to specify certain kinds of output formats.
Format keys used to specify certain kinds of output formats.
Format keys used to specify certain kinds of output formats.
# Variables
BasicFunctions are the set of initial functions provided to every template.
HeaderFunctions are used to created headers of a table.
# Interfaces
No description provided by the author