render

package
v1.5.0 Latest Latest
Warning

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

Go to latest
Published: Jul 31, 2019 License: MIT Imports: 13 Imported by: 0

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

Constants

This section is empty.

Variables

This section is empty.

Functions

func PlainError

func PlainError(w http.ResponseWriter, r *http.Request, statusCode int, err error)

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

func (Binary) ServeHTTP

func (h Binary) ServeHTTP(resp http.ResponseWriter, req *http.Request)

type Option

type Option func(*Renderer) error

func AddTemplates

func AddTemplates(files ...string) Option

AddTemplates adds filenames for the next call to parseTempaltes

func BaseTemplates

func BaseTemplates(bases ...string) Option

func FuncMap

func FuncMap(m template.FuncMap) Option

func SetLogger

func SetLogger(l log.Logger) Option

type RenderFunc

type RenderFunc func(w http.ResponseWriter, req *http.Request) (interface{}, error)

type Renderer

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

TODO: make interface

func New

func New(fs http.FileSystem, opts ...Option) (*Renderer, error)

New creates a new Renderer

func (*Renderer) Error

func (r *Renderer) Error(w http.ResponseWriter, req *http.Request, status int, err error)

func (*Renderer) GetReloader

func (r *Renderer) GetReloader() func(http.Handler) http.Handler

func (*Renderer) HTML

func (r *Renderer) HTML(name string, f RenderFunc) http.HandlerFunc

func (*Renderer) Reload

func (r *Renderer) Reload() error

func (*Renderer) Render

func (r *Renderer) Render(w http.ResponseWriter, req *http.Request, name string, status int, data interface{}) error

func (*Renderer) StaticHTML

func (r *Renderer) StaticHTML(name string) http.Handler

Jump to

Keyboard shortcuts

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