tpl

package
v0.16.0 Latest Latest
Warning

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

Go to latest
Published: Apr 30, 2025 License: GPL-3.0 Imports: 20 Imported by: 0

Documentation

Index

Constants

View Source
const INSECURE = "INSECURE"
View Source
const NOBODY = "NOBODY"

Variables

View Source
var JsFuncs = map[string]any{
	"btoa": btoa,
	"atob": atob,

	"env":       os.Getenv,
	"expandenv": os.ExpandEnv,

	"getHostByName": getHostByName,
	"fetchUrl":      fetch,
}

Template functions are also available in JavaScript runtime. Some funcs are added to it in init(). Additionally, set_status & set_body & set_header & clear_header funcs are also available in JavaScript runtime.

View Source
var TemplateFuncMap = map[string]any{
	"marshal":        marshal,
	"unmarshal":      unmarshal,
	"randstring":     randstring,
	"encrypt":        encrypt,
	"decrypt":        decrypt,
	"encrypt_binary": encrypt_binary,
	"decrypt_binary": decrypt_binary,
	"md5sum":         md5sum,
	"hexdecode":      hexdecode,
	"neg":            neg,
	"abs":            absFunc,
	"read":           read,
	"shlex_split":    shlexSplit,
	"fetch":          fetch,
	"system":         system,
	"exec":           execFunc,
}

Additional template functions, require url to be signed. Due to the pipeline way that Go template works, the last argument of funcs shoud be the primary one.

Functions

func Any2string

func Any2string(input any) string

Convert input to string. If input is nil, return empty string. If input is string or []byte, return as it. If input is a goja Promise, use it's resolved value. Otherwise return fmt.Sprint(input).

func Eval

func Eval(vm *goja.Runtime, input any) (any, error)

func ResolveGojaPromise

func ResolveGojaPromise(p *goja.Promise) (any, error)

Types

type ExecResponse

type ExecResponse struct {
	Err error
	Out string
}

type JsTpl

type JsTpl struct {
	Vm       *goja.Runtime
	Template string
}

func (*JsTpl) Execute

func (jp *JsTpl) Execute(wr io.Writer, data any) error

type Response

type Response struct {
	Err     error
	Status  int
	Header  http.Header
	Body    string
	Data    any
	RawBody io.ReadCloser
}

Jump to

Keyboard shortcuts

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