template

package
v0.6.0 Latest Latest
Warning

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

Go to latest
Published: Dec 18, 2025 License: MIT Imports: 12 Imported by: 0

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

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.

func New

func New(w io.Writer, width int, colorEnabled bool) *Template

New initializes a Template.

func (*Template) Execute

func (t *Template) Execute(input io.Reader) error

Execute applies the parsed template to the input and writes result to the writer the template was initialized with.

func (*Template) ExecuteData

func (t *Template) ExecuteData(v any) error

func (*Template) Flush

func (t *Template) Flush() error

Flush writes any remaining data to the writer. This is mostly useful when a templates uses the tablerow function but does not include the tablerender function at the end. If a template did not use the table functionality this is a noop.

func (*Template) Parse

func (t *Template) Parse(tmpl string) error

Parse the given template string for use with Execute.

func (*Template) WithFuncs

func (t *Template) WithFuncs(funcMap map[string]any) *Template

Funcs adds the elements of the argument map to the template's function map. It must be called before the template is parsed. It is legal to overwrite elements of the map including default functions. The return value is the template, so calls can be chained.

func (*Template) WithTheme

func (t *Template) WithTheme(theme string) *Template

Jump to

Keyboard shortcuts

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