-
Notifications
You must be signed in to change notification settings - Fork 2
/
middleware.go
40 lines (30 loc) · 1.07 KB
/
middleware.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
35
36
37
38
39
40
package goMiddlewareChain
import (
"context"
"net/http"
"github.com/julienschmidt/httprouter"
)
// Status represents the handler status
type Status struct {
Code int
Message string
}
// Response struct for Handlers
type Response struct {
Data interface{}
Status Status
}
// Handler represent a chainable Handler (middleware-like)
type Handler func(*Response, *http.Request, httprouter.Params)
// RestrictHandler restricts to handle following handlers
type RestrictHandler func(*Response, *http.Request, httprouter.Params) bool
// ResponseHandler required for every Endpoint
type ResponseHandler func(*Response, http.ResponseWriter, *http.Request, httprouter.Params)
// ContextHandler a handler with the go-lang-context
type ContextHandler func(context.Context, *Response, *http.Request, httprouter.Params) context.Context
// RestrictContextHandler restrict handler for contextHandler
type RestrictContextHandler func(context.Context, *Response, *http.Request, httprouter.Params) (context.Context, bool)
// ContextKey to map ContextValues
type ContextKey struct {
Key string
}