Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ( // ErrNoReferer is returned when a HTTPS request provides an empty Referer // header. ErrNoReferer = errors.New("referer not supplied") // ErrBadReferer is returned when the scheme & host in the URL do not match // the supplied Referer header. ErrBadReferer = errors.New("referer invalid") // ErrNoCSRFToken is returned if no CSRF token is supplied in the request. ErrNoCSRFToken = errors.New("CSRF token not found in request") // ErrBadCSRFToken is returned if the CSRF token in the request does not match // the token in the session, or is otherwise malformed. ErrBadCSRFToken = errors.New("CSRF token invalid") )
var PopTransaction = func(db *pop.Connection) buffalo.MiddlewareFunc { return func(h buffalo.Handler) buffalo.Handler { return func(c buffalo.Context) error { return db.Transaction(func(tx *pop.Connection) error { start := tx.Elapsed defer func() { finished := tx.Elapsed elapsed := time.Duration(finished - start) c.LogField("db", elapsed) }() c.Set("tx", tx) return h(c) }) } } }
PopTransaction is a piece of Buffalo middleware that wraps each request in a transaction that will automatically get committed or rolledback. It will also add a field to the log, "db", that shows the total duration spent during the request making database calls.
Functions ¶
func AddContentType ¶ added in v0.4.7
func AddContentType(s string) buffalo.MiddlewareFunc
AddContentType will add a secondary content type to a request. If no content type is sent by the client the default will be set, otherwise the client's content type will be used.
func CSRF ¶ added in v0.8.0
CSRF enable CSRF protection on routes using this middleware. This middleware is adapted from gorilla/csrf
func NewRelic ¶ added in v0.4.5
func NewRelic(key, name string) buffalo.MiddlewareFunc
NewRelic returns a piece of buffalo.Middleware that can be used to report requests to NewRelic. You must pass in your NewRelic key and a name for your application. If the key passed in is blank, i.e. loading from an ENV, then the middleware is skipped and the chain continues on like normal. Useful for development.
func SetContentType ¶ added in v0.4.7
func SetContentType(s string) buffalo.MiddlewareFunc
SetContentType on the request to desired type. This will override any content type sent by the client.
Types ¶
This section is empty.