render

package
v0.0.0-fd684ad Latest Latest
Warning

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

Go to latest
Published: Mar 3, 2023 License: Apache-2.0 Imports: 17 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Renderer

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

Renderer is responsible for rendering various content and templates like HTML and JSON responses. This implementation caches templates and uses a pool of buffers.

func NewRenderer

func NewRenderer(ctx context.Context, fsys fs.FS, debug bool) (*Renderer, error)

New creates a new renderer with the given details.

func (*Renderer) RenderHTML

func (r *Renderer) RenderHTML(w http.ResponseWriter, tmpl string, data any)

RenderHTML calls RenderHTMLStatus with a http.StatusOK (200).

func (*Renderer) RenderHTMLStatus

func (r *Renderer) RenderHTMLStatus(w http.ResponseWriter, code int, tmpl string, data any)

RenderHTMLStatus 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.

Jump to

Keyboard shortcuts

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