templateloader

package module
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: May 25, 2020 License: MIT Imports: 4 Imported by: 2

Documentation

Overview

Package templateloader provides different strategies for loading html templates in a web application.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type HandlerFunc

type HandlerFunc func(*template.Template, http.ResponseWriter, *http.Request)

HandlerFunc is an extension to http.HandlerFunc that takes an html template as first argument. Used in conjunction with the Loader interface.

type Loader

type Loader interface {

	// Load returns an http.HandlerFunc that passes a loaded html template to the supplied HandlerFunc.
	// name should correspond to the main template to load for this handler.
	Load(name string, h HandlerFunc, templateFiles ...string) (http.HandlerFunc, error)
}

The Loader describes a common interface for loading html templates that can be used with a HandlerFunc.

func NewOnRequestLoader

func NewOnRequestLoader() Loader

NewOnRequestLoader creates a Loader that loads and parses the template on each request. Useful for development, as changes to template files are reflected on the next request. If the template cannot be parsed, the errors will show when the resulting handler is invoked.

func NewPreloader

func NewPreloader() Loader

NewPreloader creates a Loader that loads and parses the template when Load is called. If the template cannot be parsed, an error is returned as the result of Load.

Jump to

Keyboard shortcuts

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