template

package
v0.6.3 Latest Latest
Warning

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

Go to latest
Published: Jun 10, 2025 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func RenderTemplate added in v0.4.0

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 added in v0.4.4

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 added in v0.4.0

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 added in v0.3.0

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