-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmchain.go
34 lines (24 loc) · 805 Bytes
/
mchain.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
// Package mchain provides a convenient way for middleware composition
package mchain
import (
"net/http"
)
type Middleware = func(Handler) Handler
type SimpleMiddleware = func(http.ResponseWriter, *http.Request, Handler) error
type Chain struct {
Middlewares []Middleware
}
type Handler interface {
ServeHTTP(http.ResponseWriter, *http.Request) error
}
type HandlerFunc func(http.ResponseWriter, *http.Request) error
func (f HandlerFunc) ServeHTTP(w http.ResponseWriter, r *http.Request) error {
return f(w, r)
}
type ErrorHandler = func(error, http.ResponseWriter, *http.Request)
// Std
type HttpMiddleware = func(http.Handler) http.Handler
type HttpSimpleMiddleware = func(w http.ResponseWriter, r *http.Request, next http.Handler)
type HttpChain struct {
Middlewares []HttpMiddleware
}