reverb

package module
v0.0.0-...-66ac5e2 Latest Latest
Warning

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

Go to latest
Published: Jan 29, 2018 License: MIT Imports: 21 Imported by: 0

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

Constants

This section is empty.

Variables

View Source
var AssetsPath = regexp.MustCompile("^/assets/.+")
View Source
var AuthorizeKey = "current_user"

AuthorizeKey is the name of the key that will be used to set/get the "authorization" from the `echo.Context`.

View Source
var AuthorizeRedirectURL = "/"

AuthorizeRedirectURL is the URL that the the `Authorize` middleware will redirect to for HTTP requests that require authorization, but aren't authorized.

View Source
var HeaderHTTPMethodOverride = "X-HTTP-Method-Override"

HeaderHTTPMethodOverride is the key of the HTTP header used to override the request method in `MethodOverride`.

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

func StandardHandler

func StandardHandler(h engine.Handler) http.Handler

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 NewContext(e echo.Context) *Context

func (*Context) ContentType

func (c *Context) ContentType() string

func (*Context) Err

func (c *Context) Err() error

func (*Context) Error

func (c *Context) Error(err error)

func (*Context) Extension

func (c *Context) Extension() string

func (*Context) Get

func (c *Context) Get(s string) interface{}

func (*Context) HandleError

func (c *Context) HandleError(err error) error

func (*Context) Layout

func (c *Context) Layout() string

func (*Context) LogRenderedTemplate

func (c *Context) LogRenderedTemplate(template string, fn func() error) error

func (*Context) Logger

func (c *Context) Logger() elog.Logger

func (*Context) RawRequest

func (c *Context) RawRequest() *http.Request

func (*Context) RawResponse

func (c *Context) RawResponse() http.ResponseWriter

func (*Context) Set

func (c *Context) Set(s string, i interface{})

func (*Context) SetExtension

func (c *Context) SetExtension(s string)

func (*Context) SetLayout

func (c *Context) SetLayout(s string)

func (*Context) SetValidationErrors

func (c *Context) SetValidationErrors(verrs *validate.Errors)

SetValidationErrors will add `validate.Errors` to the context using the key "validation_errors".

type Logger

type Logger struct {
	elog.Logger
	Durations durations
	Extras    extras
}

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

func NewLogger(ctx echo.Context) *Logger

NewLogger returns a `Logger` value and sets up default values such as log format, an "ID" for the request, etc...

func (*Logger) AddDurations

func (l *Logger) AddDurations(name string, ts ...time.Duration)

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.

func (*Logger) AddExtras

func (l *Logger) AddExtras(ex ...string)

AddExtras is where you can add extra data you want to print out with the final request log message.

Directories

Path Synopsis
`sess` is a package that makes dealing with sessions in an `echo` application much simplier.
`sess` is a package that makes dealing with sessions in an `echo` application much simplier.

Jump to

Keyboard shortcuts

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