Help us shape the future of Go! Take the 2026 Go Developer Survey

render

package
v0.1.0 Latest Latest
Warning

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

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

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Custom

func Custom(w http.ResponseWriter, status int, fn RenderFunc) error

Custom invokes a custom render function with status set.

func JSON

func JSON(w http.ResponseWriter, status int, payload any) error

JSON writes a JSON response.

func Text

func Text(w http.ResponseWriter, status int, message string) error

Text writes a text response.

Types

type Engine

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

Engine renders HTML templates.

func NewEngine

func NewEngine(dir, layout string) (*Engine, error)

NewEngine builds a template engine and loads templates.

func NewEngineFromFS

func NewEngineFromFS(fsys fs.FS, dir string, options Options) (*Engine, error)

NewEngineFromFS builds a template engine from an fs.FS.

func NewEngineWithOptions

func NewEngineWithOptions(dir string, options Options) (*Engine, error)

NewEngineWithOptions builds a template engine with options.

func (*Engine) AddFuncs

func (e *Engine) AddFuncs(funcs FuncMap) error

AddFuncs registers template functions.

func (*Engine) Load

func (e *Engine) Load() error

Load parses templates.

func (*Engine) Render

func (e *Engine) Render(w http.ResponseWriter, status int, name string, data any) error

Render writes a template response.

type FuncMap

type FuncMap = template.FuncMap

FuncMap defines template functions.

type Options

type Options struct {
	Layout string
	Funcs  FuncMap
	Reload bool
	// DevDir loads templates from disk when Reload is enabled (useful with embedded templates).
	DevDir string
	// IncludeSubdirs enables loading templates from nested directories.
	IncludeSubdirs bool
	// Partials lists glob patterns (relative to the templates dir) treated as partials.
	Partials []string
}

Options configures the template engine.

type RenderFunc

type RenderFunc func(http.ResponseWriter) error

RenderFunc allows custom rendering.

Jump to

Keyboard shortcuts

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