gotemplate

package module
v0.5.3 Latest Latest
Warning

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

Go to latest
Published: Jun 29, 2022 License: MIT Imports: 22 Imported by: 0

README

Generic Go Template funcs

Usage:

import ( 
    "github.com/gpmd/gotemplate"
)

func main() {
    gotemplate.Template("{{(xml_decode .).mycode}}", "<?xml version=\"1.0\"?><mycode>MYCODE</mycode>")
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetFuncs

func GetFuncs() []string

GetFuncs will return all usable template funcs as string slice

func MustProcessTemplateFile

func MustProcessTemplateFile(template string, bundle interface{}) string

MustProcessTemplateFile processes golang template file otherwise panics

func MustTemplate

func MustTemplate(str string, data interface{}) string

MustTemplate parses string as Go template, using data as scope

func ProcessTemplateFile

func ProcessTemplateFile(template string, bundle interface{}) ([]byte, error)

ProcessTemplateFile processes golang template file

func RegisterFS

func RegisterFS(filesystem afero.Fs)

RegisterFS (afero) virtual filesystem for ProcessTemplateFile

func RegisterFunc

func RegisterFunc(key string, templatefunc interface{})

RegisterFunc registers a new template func to the template parser

func Template

func Template(str string, data interface{}) (string, error)

Template parses string as Go template, using data as scope

func TemplateDelim

func TemplateDelim(str string, data interface{}, begin, end string) (string, error)

TemplateDelim parses string with custom delimiters as Go template, using data as scope

Types

type Parser

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

Parser is the main type

func NewParser

func NewParser() *Parser

NewParser defines a new parser

func (*Parser) ParseStruct

func (l *Parser) ParseStruct(content io.Reader, format string) (interface{}, error)

ParseStruct parses byte slice into map or slice

func (*Parser) ReadStruct

func (l *Parser) ReadStruct(filename, format string) (interface{}, error)

ReadStruct reads from given file, parsing into structure

func (*Parser) RegisterParser

func (l *Parser) RegisterParser(format string, parser ParserFunc)

RegisterParser registers or overrides a format parser func. Indices are lower case.

type ParserFunc

type ParserFunc func(io.Reader) (interface{}, error)

ParserFunc is to parse a []byte into an interface{}

Jump to

Keyboard shortcuts

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