template

package
v0.217.1 Latest Latest
Warning

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

Go to latest
Published: Jun 2, 2025 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Overview

Package template provides a common set of tools around Go templates that help with converting data in other formats to GOBL documents.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Indent

func Indent(count int, text string) string

Indent takes the text, finds all matching `\n`, and adds *two* spaces immediately after for each of the provided counts. This is useful for indenting variables as blocks of text to be correctly presented in YAML files.

Example YAML block:

rsa_key: |-
  {{ .Key | indent 1 }}

func Optional

func Optional(in any) string

Optional is useful when outputting strings to ensure that nil values are outputted correctly.

Types

type Template

type Template struct {
	// contains filtered or unexported fields
}

Template contains a GOBL template document prepared for interpolating with incoming rows or objects of data.

func Must

func Must(t *Template, err error) *Template

Must is a helper function that wraps a call to a function returning (*Template, error) and panics if the error is non-nil. It is intended for use in variable initializations such as

var t = template.Must(template.New("name", "..data.."))

func New

func New(name, data string) (*Template, error)

New defines a new template with the given name and data.

func (*Template) Execute

func (t *Template) Execute(data any) (any, error)

Execute takes the given data and interpolates it into the template to generate a GOBL Envelope or Schema Object according to the schema defined in the template.

Jump to

Keyboard shortcuts

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