templates

package
Version: v0.0.0-...-517fb07 Latest Latest
Warning

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

Go to latest
Published: Sep 24, 2021 License: MIT Imports: 20 Imported by: 0

Documentation

Index

Constants

View Source
const DefaultPoolSize = 1

Variables

View Source
var JSONSerializeFuncs = template.FuncMap{
	"json": func(v interface{}) (string, error) {
		return marshal(v, false, false)
	},

	"json_indent": func(v interface{}) (string, error) {
		return marshal(v, true, false)
	},

	"json_indent_quote": func(v interface{}) (string, error) {
		return marshal(v, true, true)
	},

	"get": func(v interface{}, path string, defaultValue interface{}) (interface{}, error) {
		return get_impl(v, path, defaultValue)
	},
}

JSONSerializeFuncs are additional funcs for using from text/template. for example for embedding whole object as JSON into another JSON

Functions

func Init

func Init(poolSize int) (err error)

func LoadTemplateScript

func LoadTemplateScript(script string, extraFunctions template.FuncMap) (func(map[string]interface{}) (interface{}, error), error)

LoadTemplateScript loads script into newly created Javascript vm Returns func that is mapped to javascript function inside vm instance

func ProcessEvent

func ProcessEvent(function func(map[string]interface{}) (interface{}, error), event map[string]interface{}) (result interface{}, err error)

ProcessEvent runs javascript function loaded into specified vm on provided event object

func ToJSON

func ToJSON(responseObject interface{}) ([]byte, error)

func ToString

func ToString(responseObject interface{}, allowArray bool, allowObject bool, truncateDate bool) string

func Transform

func Transform(src string) (string, error)

Transform transforms javascript to ES5 compatible code + adds few tweaks to loosen some rules

func TransformReader

func TransformReader(src io.Reader, opts map[string]interface{}) (io.Reader, error)

func TransformString

func TransformString(src string, opts map[string]interface{}) (string, error)

Types

type TemplateExecutor

type TemplateExecutor interface {
	ProcessEvent(events.Event) (interface{}, error)
	Format() string
	Expression() string
	Close()
}

func SmartParse

func SmartParse(name string, expression string, extraFunctions template.FuncMap) (TemplateExecutor, error)

SmartParse is a factory method that returns TemplateExecutor implementation based on provided expression language

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
t or T : Toggle theme light dark auto
y or Y : Canonical URL