middleware
v0.0.0-20191115102631-69ee5db2c99e
Documentation
pkg.go.dev ↗Constants
CtxRequestIDKey
const CtxRequestIDKey ctxRequestIDKeyType = 0
Variables
DefaultJWTContextKey
var ( DefaultJWTContextKey = "user" )
Functions
Basic
func Basic() lion.Middlewares
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.
JWTEnsureAuthenticated
func JWTEnsureAuthenticated(contextKey interface{}) lion.Middleware
NewLogger
func NewLogger() lion.Middleware
NewLogger creates a new Logger
NewNoCache
func NewNoCache() lion.Middleware
NoCache middleware sets headers to disable browser caching. Inspired by https://github.com/mytrile/nocache
NewRealIP
func NewRealIP() lion.Middleware
NewRecovery
func NewRecovery() lion.Middleware
NewRecovery creates a new Recovery instance
NewStatic
func NewStatic(directory http.FileSystem) lion.Middleware
NewStatic returns a new instance of Static
Types
JWT
type JWT struct {
SigningKey interface{}
SigningMethod string
ContextKey interface{}
}
NewJWT
func NewJWT(secret []byte) *JWT
JWT.EnsureAuthenticated
func (j *JWT) EnsureAuthenticated() lion.Middleware
JWT.ServeNext
func (j *JWT) ServeNext(next http.Handler) http.Handler
Logger
type Logger struct {
*log.Logger
}
Logger is a middlewares that logs incoming http requests
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.
MaxAge
type MaxAge struct {
Duration time.Duration
Filter func(r *http.Request) bool
}
MaxAge.ServeNext
func (m *MaxAge) ServeNext(next http.Handler) http.Handler
MaxAge is a middleware that defines the max duration headers
NoCache
type NoCache struct {
ResponseHeaders map[string]string
EtagHeaders []string
}
NoCache.ServeNext
func (n NoCache) ServeNext(next http.Handler) http.Handler
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
RealIP.ServeNext
func (RealIP) ServeNext(next http.Handler) http.Handler
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
Recovery.ServeNext
func (rec *Recovery) ServeNext(next http.Handler) http.Handler
ServeNext is the method responsible for recovering from a panic
RequestID
type RequestID struct {
SetHeader bool
// contains filtered or unexported fields
}
NewRequestID
func NewRequestID() *RequestID
RequestID.ServeNext
func (rid *RequestID) ServeNext(next http.Handler) http.Handler
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
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
Static.ServeNext
func (s *Static) ServeNext(next http.Handler) http.Handler
ServeNext tries to find a file in the directory