Documentation
¶
Overview ¶
Package template facilitates processing of JSON strings using Go templates. Provides additional functions not available using basic Go templates, such as coloring, and table rendering.
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Template ¶
type Template struct {
// contains filtered or unexported fields
}
Template is the representation of a template.
Example ¶
// Information about the terminal can be obtained using the [pkg/term] package. colorEnabled := true termWidth := 14 json := strings.NewReader(heredoc.Doc(`[ {"number": 1, "title": "One"}, {"number": 2, "title": "Two"} ]`)) template := "HEADER\n\n{{range .}}{{tablerow .number .title}}{{end}}{{tablerender}}\nFOOTER" tmpl := New(os.Stdout, termWidth, colorEnabled) if err := tmpl.Parse(template); err != nil { log.Fatal(err) } if err := tmpl.Execute(json); err != nil { log.Fatal(err) }
Output: HEADER 1 One 2 Two FOOTER
func (*Template) Execute ¶
Execute applies the parsed template to the input and writes result to the writer the template was initialized with.
Click to show internal directories.
Click to hide internal directories.