Documentation ¶
Overview ¶
`reverb` is a set of middleware, tools, and other functions that make working with "github.com/labstack/echo" applications much, much easier!
It includes things such as loggers, authorization, error handling, etc...
Index ¶
- Variables
- func Authorize(handler echo.HandlerFunc) echo.HandlerFunc
- func ClearContext(handler echo.HandlerFunc) echo.HandlerFunc
- func DefaultContentType(s string) echo.MiddlewareFunc
- func MethodOverride(app http.Handler) http.HandlerFunc
- func RequestLogger(next echo.HandlerFunc) echo.HandlerFunc
- func StandardHandler(h engine.Handler) http.Handler
- type Context
- func (c *Context) ContentType() string
- func (c *Context) Err() error
- func (c *Context) Error(err error)
- func (c *Context) Extension() string
- func (c *Context) Get(s string) interface{}
- func (c *Context) HandleError(err error) error
- func (c *Context) Layout() string
- func (c *Context) LogRenderedTemplate(template string, fn func() error) error
- func (c *Context) Logger() elog.Logger
- func (c *Context) RawRequest() *http.Request
- func (c *Context) RawResponse() http.ResponseWriter
- func (c *Context) Set(s string, i interface{})
- func (c *Context) SetExtension(s string)
- func (c *Context) SetLayout(s string)
- func (c *Context) SetValidationErrors(verrs *validate.Errors)
- type Logger
Constants ¶
This section is empty.
Variables ¶
var AssetsPath = regexp.MustCompile("^/assets/.+")
var AuthorizeKey = "current_user"
AuthorizeKey is the name of the key that will be used to set/get the "authorization" from the `echo.Context`.
var AuthorizeRedirectURL = "/"
AuthorizeRedirectURL is the URL that the the `Authorize` middleware will redirect to for HTTP requests that require authorization, but aren't authorized.
var HeaderHTTPMethodOverride = "X-HTTP-Method-Override"
HeaderHTTPMethodOverride is the key of the HTTP header used to override the request method in `MethodOverride`.
var ParamHTTPMethodOverride = "_method"
ParamHTTPMethodOverride is the form value used to override the request method in `MethodOverride`.
Functions ¶
func Authorize ¶
func Authorize(handler echo.HandlerFunc) echo.HandlerFunc
Authorize is an `echo` middleware that will check to make sure the `AuthorizeKey` variable is set in the `echo.Context`. If the key is not set it will redirect to the `AuthorizeRedirectURL` if the request is HTTP. If the request is of type `application/json` the a new `http.StatusForbidden` will be thrown.
func ClearContext ¶
func ClearContext(handler echo.HandlerFunc) echo.HandlerFunc
ClearContext is an `echo` middle that clears the `echo.Context` at the end of a request. You should DEFINITELY add this to your middleware stack! If you don't, you run the risk of memory bloat!
func DefaultContentType ¶
func DefaultContentType(s string) echo.MiddlewareFunc
DefautlContentType is an `echo` middleware that will the request "Content-Type" header to the specified type if the header is not already set.
func MethodOverride ¶
func MethodOverride(app http.Handler) http.HandlerFunc
MethodOverride allows requests that don't support HTTP methods such as "PUT", "PATCH", "DELETE", to use either a header, `HeaderHTTPMethodOverride`, or a form value, `ParamHTTPMethodOverride`, to change the request method.
func RequestLogger ¶
func RequestLogger(next echo.HandlerFunc) echo.HandlerFunc
RequestLogger is an `echo` middleware that wraps a request and nicely formats it using the `reverb.Logger`.
Types ¶
type Context ¶
type Context struct { echo.Context Data map[string]interface{} Session *sess.Session RenderedTemplates []string // contains filtered or unexported fields }
func NewContext ¶
func (*Context) ContentType ¶
func (*Context) HandleError ¶
func (*Context) LogRenderedTemplate ¶
func (*Context) RawRequest ¶
func (*Context) RawResponse ¶
func (c *Context) RawResponse() http.ResponseWriter
func (*Context) SetExtension ¶
func (*Context) SetValidationErrors ¶
SetValidationErrors will add `validate.Errors` to the context using the key "validation_errors".
type Logger ¶
Logger gives you all the benefits of a `log.Logger`, but it also let's you log durations as well as extra logging data that will all get printed out nicely at the end of a request.
func NewLogger ¶
NewLogger returns a `Logger` value and sets up default values such as log format, an "ID" for the request, etc...
func (*Logger) AddDurations ¶
AddDurations let's you add `n` `time.Duration` values to a particular key. For example you could log multiple database requests to a single key, or log multiple page rendering times to a key. These durations will all be rolled up to one duration for that key when printed out in the log.