template

package
v0.17.3 Latest Latest
Warning

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

Go to latest
Published: Apr 14, 2024 License: Apache-2.0 Imports: 17 Imported by: 0

Documentation

Overview

Package template implements data-driven templates for generating a value.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Execute

func Execute(ctx context.Context, i, data interface{}) (interface{}, error)

Execute executes templates of i with data.

Types

type Func

type Func interface {
	Exec(arg interface{}) (interface{}, error)
	UnmarshalArg(unmarshal func(interface{}) error) (interface{}, error)
}

Func represents a left arrow function.

type FuncCall added in v0.17.0

type FuncCall struct {
	Func
}

FuncCall represents a left arrow function call like '{{func <-}}'.

func (*FuncCall) Do added in v0.17.0

func (f *FuncCall) Do(ctx context.Context, v, data any) (any, error)

Do executes the function f. This function executes templates of the argument v with data before calling the function f.

type Lazy added in v0.17.0

type Lazy func(any) (any, error)

Lazy represents a value with lazy initialization. You can create a Lazy value by using $.

type Template

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

Template is the representation of a parsed template.

func New

func New(str string) (*Template, error)

New parses text as a template and returns it.

func (*Template) Execute

func (t *Template) Execute(ctx context.Context, data interface{}) (interface{}, error)

Execute applies a parsed template to the specified data. If the Lazy isn't called, the context value should be canceled to avoid a goroutine leak.

Directories

Path Synopsis
Package ast declares the types used to represent syntax trees.
Package ast declares the types used to represent syntax trees.
Package parser implements a parser for a template string.
Package parser implements a parser for a template string.
Package token defines constants representing the lexical tokens.
Package token defines constants representing the lexical tokens.

Jump to

Keyboard shortcuts

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