render

package
v0.3.3 Latest Latest
Warning

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

Go to latest
Published: Feb 24, 2024 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const HdrHtml = "text/html"

Variables

This section is empty.

Functions

func AllowedResponseCode

func AllowedResponseCode(code int) bool

AllowedResponseCode returns true if the code is a permitted response code, false otherwise.

func Html

func Html(w http.ResponseWriter, r *http.Request, tmpl string, data any)

Html calls HtmlStatus with a http.StatusOK (200).

func Html500

func Html500(w http.ResponseWriter, r *http.Request, err error)

Html500 renders the given error as Html. In production mode, this always renders a generic "server error" message. In isDebug, it returns the actual error from the caller.

func HtmlNoContent

func HtmlNoContent(w http.ResponseWriter)

HtmlNoContent sets 204 status code

func HtmlStatus

func HtmlStatus(w http.ResponseWriter, r *http.Request, statusCode int, tmpl string, data any)

HtmlStatus renders the given Html template by name. It attempts to gracefully handle any rendering errors to avoid partial responses sent to the response by writing to a buffer first, then flushing the buffer to the response.

If template rendering fails, a generic 500 page is returned. In dev mode, the error is included on the page. If flushing the buffer to the response fails, an error is logged, but no recovery is attempted.

The buffers are fetched via a sync.Pool to reduce allocations and improve performance.

func LoadTemplates

func LoadTemplates() error

LoadTemplates loads or reloads all templates.

func SetDebug

func SetDebug(v bool)

func SetFileSystem

func SetFileSystem(fsys fs.FS)

Types

This section is empty.

Jump to

Keyboard shortcuts

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