middleware

package
v2.0.0-...-64ca040 Latest Latest
Warning

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

Go to latest
Published: Nov 29, 2016 License: MIT Imports: 18 Imported by: 0

Documentation

Index

Constants

View Source
const CtxRequestIDKey ctxRequestIDKeyType = 0

Variables

View Source
var (
	DefaultJWTContextKey = "user"
)

Functions

func Basic

func Basic() lion.Middlewares

func Classic

func Classic() lion.Middlewares

Classic creates a new router instance with default middlewares: Recovery, RealIP, Logger. The static middleware instance is initiated with a directory named "public" located relatively to the current working directory.

func JWTEnsureAuthenticated

func JWTEnsureAuthenticated(contextKey interface{}) lion.Middleware

func NewLogger

func NewLogger() lion.Middleware

NewLogger creates a new Logger

func NewNoCache

func NewNoCache() lion.Middleware

NoCache middleware sets headers to disable browser caching. Inspired by https://github.com/mytrile/nocache

func NewRealIP

func NewRealIP() lion.Middleware

func NewRecovery

func NewRecovery() lion.Middleware

NewRecovery creates a new Recovery instance

func NewStatic

func NewStatic(directory http.FileSystem) lion.Middleware

NewStatic returns a new instance of Static

Types

type JWT

type JWT struct {
	SigningKey    interface{}
	SigningMethod string
	ContextKey    interface{}
}

func NewJWT

func NewJWT(secret []byte) *JWT

func (*JWT) EnsureAuthenticated

func (j *JWT) EnsureAuthenticated() lion.Middleware

func (*JWT) ServeNext

func (j *JWT) ServeNext(next http.Handler) http.Handler

type Logger

type Logger struct {
	*log.Logger
}

Logger is a middlewares that logs incoming http requests

func (*Logger) ServeNext

func (l *Logger) ServeNext(next http.Handler) http.Handler

ServeNext implements the Middleware interface for Logger. It wraps the corresponding http.ResponseWriter and saves statistics about the status code returned, the number of bytes written and the time that requests took.

type MaxAge

type MaxAge struct {
	Duration time.Duration
	Filter   func(r *http.Request) bool
}

func (*MaxAge) ServeNext

func (m *MaxAge) ServeNext(next http.Handler) http.Handler

MaxAge is a middleware that defines the max duration headers

type NoCache

type NoCache struct {
	ResponseHeaders map[string]string
	EtagHeaders     []string
}

func (NoCache) ServeNext

func (n NoCache) ServeNext(next http.Handler) http.Handler

type RealIP

type RealIP struct{}

RealIP is a middleware that sets a http.Request's RemoteAddr to the results of parsing either the X-Forwarded-For header or the X-Real-IP header (in that order).

This middleware should be inserted fairly early in the middleware stack to ensure that subsequent layers (e.g., request loggers) which examine the RemoteAddr will see the intended value.

You should only use this middleware if you can trust the headers passed to you (in particular, the two headers this middleware uses), for example because you have placed a reverse proxy like HAProxy or nginx in front of Goji. If your reverse proxies are configured to pass along arbitrary header values from the client, or if you use this middleware without a reverse proxy, malicious clients will be able to make you very sad (or, depending on how you're using RemoteAddr, vulnerable to an attack of some sort). Taken from https://github.com/zenazn/goji/blob/master/web/middleware/realip.go

func (RealIP) ServeNext

func (RealIP) ServeNext(next http.Handler) http.Handler

type Recovery

type Recovery struct {
	Logger     *log.Logger
	PrintStack bool
	StackAll   bool
	StackSize  int
}

Recovery is a middleware that recovers from panics Taken from https://github.com/codegangsta/negroni/blob/master/recovery.go

func (*Recovery) ServeNext

func (rec *Recovery) ServeNext(next http.Handler) http.Handler

ServeNext is the method responsible for recovering from a panic

type RequestID

type RequestID struct {
	SetHeader bool
	// contains filtered or unexported fields
}

func NewRequestID

func NewRequestID() *RequestID

func (*RequestID) ServeNext

func (rid *RequestID) ServeNext(next http.Handler) http.Handler

type ResponseWriter

type ResponseWriter interface {
	http.ResponseWriter
	http.Flusher
	http.Hijacker
	Status() int
	BytesWritten() int
	Tee(io.Writer)
	Unwrap() http.ResponseWriter
}

ResponseWriter is the proxy responseWriter

type Static

type Static struct {
	// Dir is the directory to serve static files from
	Dir http.FileSystem
	// Prefix is the optional prefix used to serve the static directory content
	Prefix string
	// IndexFile defines which file to serve as index if it exists.
	IndexFile string
}

Static is a middleware handler that serves static files in the given directory/filesystem. Taken from https://github.com/codegangsta/negroni/blob/master/static.go

func (*Static) ServeNext

func (s *Static) ServeNext(next http.Handler) http.Handler

ServeNext tries to find a file in the directory

Jump to

Keyboard shortcuts

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