render

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Dec 30, 2023 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package render provides functionality for rendering HTML when building web applications.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ContextualFuncMap

type ContextualFuncMap func(w http.ResponseWriter, r *http.Request) template.FuncMap

A ContextualFuncMap is a function that returns an HTML template.FuncMap.

It is used to provide a renderer with template function that have request-scoped data.

type Options

type Options struct {
	// The directory to serve templates from. Default is "templates".
	Dir string

	// The template to use as a layout. Layouts can call {{ yield }}. Defaults
	// to an empty string (meaning a layout is not used).
	Layout string

	// Request-scoped template funcs. Default is nil.
	Funcs []ContextualFuncMap

	// Whether or not to recompile templates. Default is false. Do not
	// recompile templates in production, as this adds a significant
	// performance penalty.
	Reload bool
}

type Render

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

func New

func New(o *Options) *Render

func (*Render) HTML

func (r *Render) HTML(w io.Writer, req *http.Request, name string, data map[string]interface{}, opts ...RenderOptions)

HTML renders the HTML template with the given name. The HTTP request is optional, and can be set to nil. It is only used to add request-specific context to HTML template functions.

func (*Render) TextError

func (r *Render) TextError(w io.Writer, error string, code int)

TextError writes the given error message as a plain text response.

type RenderOptions

type RenderOptions struct {
	Layout     string
	StatusCode int
	Headers    map[string]string
}

Jump to

Keyboard shortcuts

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