Documentation ¶
Index ¶
- Variables
- func DefaultMinifier() *minify.M
- func HandleJSON(fn func(rw http.ResponseWriter, req *http.Request) interface{}) http.HandlerFunc
- func WithContextMiddleware(c context.Context) func(http.Handler) http.Handler
- type AssetLoader
- type AssetLoaderChain
- type MonitoringMiddleware
- type PackrBox
- type Site
- type StatusError
Constants ¶
This section is empty.
Variables ¶
var ErrNotFound = errors.New("asset not found")
ErrNotFound is a sentinel error returned by an AssetLoader when the asset is not defined.
Functions ¶
func DefaultMinifier ¶
DefaultMinifier is a default minifier configuration to use.
func HandleJSON ¶
func HandleJSON(fn func(rw http.ResponseWriter, req *http.Request) interface{}) http.HandlerFunc
HandleJSON returns an http.HandlerFunc that accepts a JSON request and returns a JSON response object.
Types ¶
type AssetLoader ¶
type AssetLoader interface { // Load loads the specified asset. If the asset couldn't be found, Load // should return ErrNotFound. Load(name string) ([]byte, error) }
AssetLoader is a generic interface to something that returns asset data by name.
type AssetLoaderChain ¶
type AssetLoaderChain []AssetLoader
AssetLoaderChain is a chain of asset loaders. It iterates through each AssetLoader attempting to load the named asset. If one AssetLoader returns ErrNotFound, the next loader in the chain is consulted.
type MonitoringMiddleware ¶
type MonitoringMiddleware struct { // Logger, is not nil, is the logger to use. Logger *zap.Logger }
MonitoringMiddleware exposes a chainable http.Handler middleware method that offers HTTP server monitoring.
func (*MonitoringMiddleware) Middleware ¶
func (lh *MonitoringMiddleware) Middleware(next http.Handler) http.Handler
Middleware wraps next in before and after monitoring middleware.
type Site ¶
type Site struct { // Logger, if not nil, is the logger to use during Site operations. Logger *zap.Logger // Cache, if true, instructs the Site to cache any data or templates that it // loads. Cache bool // Roots is the set of path roots, used to load templates and other content. Roots map[string]AssetLoader // TemplateFuncMap is a map of functions that get injected into each template. TemplateFuncMap template.FuncMap // contains filtered or unexported fields }
Site is a basic web site instance.
func (*Site) AddTemplate ¶
AddTemplate adds a template registration to s.
func (*Site) RenderTemplate ¶
RenderTemplate renders the specified template to w.
RenderTemplate is not safe to call concurrently with AddTemplate; however, it is safe to call concurrently otherwise.
func (*Site) RenderWithError ¶
func (s *Site) RenderWithError(rw http.ResponseWriter, ct string, fn func() error)
RenderWithError calls fn. If fn returns an error, RenderWithError will write it to the ResponseWriter, setting the appropriate status if possible.
If a StatusError is returned, it is rendered specially, with its code being used. Otherwise, http.StatusInternalServerError will be used.
type StatusError ¶
StatusError is a sentinel error sent to RenderWithError to indicate that a specific HTTP return code should be returned.
func (*StatusError) Error ¶
func (se *StatusError) Error() string