tmpl

package
v0.6.1 Latest Latest
Warning

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

Go to latest
Published: Jan 13, 2025 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type StrTmpl added in v0.4.0

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

func MustNewStrTmpl added in v0.4.0

func MustNewStrTmpl(tmplRaw string) *StrTmpl

MustNewStrTmpl creates a new StrTmpl from the provided raw template string. It takes tmplRaw of type string. It returns a pointer to StrTmpl. It panics if there is an error during the creation of the StrTmpl.

func NewStrTmpl added in v0.4.0

func NewStrTmpl(tmpl string) (*StrTmpl, error)

NewStrTmpl creates a new StrTmpl instance by parsing the provided template string. It takes tmpl of type string, which is the template to be parsed. It returns a pointer to StrTmpl and an error. It returns an error if the template parsing fails.

func (*StrTmpl) Execute added in v0.4.0

func (t *StrTmpl) Execute(params any) (string, error)

Execute processes the given parameters using a JSON template and returns the resulting string. It takes params of type any, which represents the data to be used in the template. It returns a string containing the processed template and an error if the operation fails. It returns an error if the parameters cannot be marshaled into JSON, if the template execution fails, or if the template path does not resolve to a string.

type Tmpl

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

func MustNewTmpl added in v0.3.0

func MustNewTmpl(tmplRaw string) *Tmpl

MustNewTmpl creates a new Tmpl instance from the provided raw template string. It takes tmplRaw of type string, which is the raw template content. It returns a pointer to a Tmpl instance. It panics if there is an error during the creation of the Tmpl instance.

func New

func New(tmplRaw string) (*Tmpl, error)

New creates a new Tmpl instance from a raw JSON template string. It takes tmplRaw of type string, which is the raw JSON template. It returns a pointer to Tmpl and an error. It returns an error if the template parsing fails.

func (*Tmpl) Execute

func (t *Tmpl) Execute(params any) ([]byte, error)

Execute processes the provided data using the template and returns the result as a byte slice. It takes one parameter: data of type []byte, which represents the input data to be processed by the template. It returns a byte slice containing the processed data and an error if the template execution fails. It returns an error if the template execution encounters any issues, such as invalid data or template errors.

type URLTmpl added in v0.3.0

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

func MustNewURLTmpl added in v0.3.0

func MustNewURLTmpl(tmplRaw string) *URLTmpl

MustNewURLTmpl creates a new URLTmpl from the given raw template string. It takes tmplRaw of type string. It returns a pointer to a URLTmpl. It panics if the template string is invalid or if there is an error during the creation of the URLTmpl.

func NewURLTmpl added in v0.3.0

func NewURLTmpl(tmpl string) (*URLTmpl, error)

NewURLTmpl creates a new URLTmpl instance by parsing the provided template string. It takes tmpl of type string, which represents the template to be parsed. It returns a pointer to a URLTmpl and an error. It returns an error if the template parsing fails.

func (*URLTmpl) Execute added in v0.3.0

func (t *URLTmpl) Execute(params any) (string, error)

Execute generates a URL string by executing a template with the provided parameters. It takes params of type any, which are marshaled into JSON and used to fill the template. It returns a string containing the generated URL and an error if the operation fails. It returns an error if the parameters cannot be marshaled into JSON, if the template execution fails, or if the template path does not resolve to a string value.

Jump to

Keyboard shortcuts

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