Documentation ¶
Overview ¶
Package render implements template inheritance and exposes functions to render HTML.
inspired by http://elithrar.github.io/article/approximating-html-template-inheritance and https://github.com/sourcegraph/thesrc/blob/master/app/handler.go
It also exports two types Binary and HMTL. Both wrap a http.HandlerFunc-like function with an error return value and argument the response.
Index ¶
- func PlainError(w http.ResponseWriter, r *http.Request, statusCode int, err error)
- type Binary
- type ErrorHandlerFunc
- type FuncInjector
- type Option
- func AddTemplates(files ...string) Option
- func BaseTemplates(bases ...string) Option
- func ErrorTemplate(name string) Option
- func FuncMap(m template.FuncMap) Option
- func InjectTemplateFunc(name string, fn FuncInjector) Option
- func SetErrorHandler(fn ErrorHandlerFunc) Option
- func SetLogger(l log.Logger) Option
- type RenderFunc
- type Renderer
- func (r *Renderer) Error(w http.ResponseWriter, req *http.Request, status int, err error)
- func (r *Renderer) GetReloader() func(http.Handler) http.Handler
- func (r *Renderer) HTML(name string, f RenderFunc) http.HandlerFunc
- func (r *Renderer) Reload() error
- func (r *Renderer) Render(w http.ResponseWriter, req *http.Request, name string, status int, ...) error
- func (r *Renderer) StaticHTML(name string) http.Handler
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func PlainError ¶
PlainError helps rendering user errors
Types ¶
type Binary ¶
type Binary func(resp http.ResponseWriter, req *http.Request) error
Binary sets Content-Description and Content-Transfer-Encoding if h returns an error it returns http status 500
type ErrorHandlerFunc ¶ added in v1.10.0
ErrorHandlerFunc is just like http.HandlerFunc but with an additional status code and error
type FuncInjector ¶ added in v1.6.0
FuncInjector needs to return a function that is admissible for (html/template).FuncMap
type Option ¶
func AddTemplates ¶
AddTemplates adds filenames for the next call to parseTempaltes
func BaseTemplates ¶
func ErrorTemplate ¶ added in v1.8.0
ErrorTemplate sets the filename of template that should be used for errors.
func InjectTemplateFunc ¶ added in v1.6.0
func InjectTemplateFunc(name string, fn FuncInjector) Option
InjectTemplateFunc sets template functions, just like FuncMap. But in comparrison, these here are evaluated once with the request before being assigned to the template. This allows for accessing the requests cookies or headers, for instance.
func SetErrorHandler ¶ added in v1.10.0
func SetErrorHandler(fn ErrorHandlerFunc) Option
overwrites the default error handler and allows for inspecting errors before rendering them
type RenderFunc ¶
type RenderFunc func(w http.ResponseWriter, req *http.Request) (interface{}, error)
type Renderer ¶
type Renderer struct {
// contains filtered or unexported fields
}
func New ¶
func New(fs http.FileSystem, opts ...Option) (*Renderer, error)
New creates a new Renderer
func (*Renderer) HTML ¶
func (r *Renderer) HTML(name string, f RenderFunc) http.HandlerFunc