template

package
v0.9.2 Latest Latest
Warning

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

Go to latest
Published: Jan 19, 2026 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NormalizeJSONStringValues added in v0.8.0

func NormalizeJSONStringValues(args map[string]any)

func RenderTemplate

func RenderTemplate(tmpl string, ctx *Context) (string, error)

RenderTemplate renders a template with the given context

Types

type Context

type Context struct {
	Args     map[string]any      `json:"args"`
	Config   map[string]string   `json:"config"`
	Request  RequestWrapper      `json:"request"`
	Response ResponseWrapper     `json:"response"`
	Env      func(string) string `json:"-"` // Function to get environment variables
}

Context represents the template context

func AssembleTemplateContext

func AssembleTemplateContext(req *RequestWrapper, args map[string]any, serverCfg map[string]string) (*Context, error)

func NewContext

func NewContext() *Context

NewContext creates a new template context

func PrepareTemplateContext

func PrepareTemplateContext(requestMeta *session.RequestInfo, args map[string]any, request *http.Request, serverCfg map[string]string) (*Context, error)

PrepareTemplateContext prepares the template context with request and config data

type Renderer

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

Renderer is responsible for rendering templates

func NewRenderer

func NewRenderer() *Renderer

NewRenderer creates a new template renderer

func (*Renderer) Render

func (r *Renderer) Render(tmpl string, ctx *Context) (string, error)

Render renders a template with the given context

type RequestWrapper

type RequestWrapper struct {
	Headers map[string]string `json:"headers"`
	Query   map[string]string `json:"query"`
	Cookies map[string]string `json:"cookies"`
	Path    map[string]string `json:"path"`
	Body    map[string]any    `json:"body"`
}

Context represents the template context

type ResponseWrapper

type ResponseWrapper struct {
	Data any `json:"data"`
	Body any `json:"body"`
}

Context represents the template context

Jump to

Keyboard shortcuts

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