web

package
v0.0.0-...-8d9275d Latest Latest
Warning

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

Go to latest
Published: Apr 20, 2018 License: MIT Imports: 20 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
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

func DefaultMinifier() *minify.M

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.

func WithContextMiddleware

func WithContextMiddleware(c context.Context) func(http.Handler) http.Handler

WithContextMiddleware is a gorilla/mux middleware Handle that adds the supplied Context to each http.Request that gets handled.

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.

func (AssetLoaderChain) Load

func (alc AssetLoaderChain) Load(name string) ([]byte, error)

Load implements AssetLoader.

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 PackrBox

type PackrBox struct {
	packr.Box
}

PackrBox is an AssetLoader that loads from a packr.Box.

func (*PackrBox) Load

func (pb *PackrBox) Load(name string) ([]byte, error)

Load implements AssetLoader.

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

func (s *Site) AddTemplate(name string, dependencies ...string) error

AddTemplate adds a template registration to s.

func (*Site) Render

func (s *Site) Render(w io.Writer, name string) error

Render renders the specified asset to w.

func (*Site) RenderTemplate

func (s *Site) RenderTemplate(w io.Writer, name string, data interface{}) error

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

type StatusError struct {
	Err  error
	Code int
}

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

Directories

Path Synopsis
Package bootstrap exposes a bundle containing Twitter Bootstrap files.
Package bootstrap exposes a bundle containing Twitter Bootstrap files.

Jump to

Keyboard shortcuts

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