-
Notifications
You must be signed in to change notification settings - Fork 26
/
middleware.go
46 lines (38 loc) · 1.11 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
41
42
43
44
45
46
package permissions
import (
"net/http"
"github.com/appbaseio/reactivesearch-api/middleware"
"github.com/appbaseio/reactivesearch-api/middleware/classify"
"github.com/appbaseio/reactivesearch-api/middleware/validate"
"github.com/appbaseio/reactivesearch-api/model/category"
"github.com/appbaseio/reactivesearch-api/plugins/auth"
"github.com/appbaseio/reactivesearch-api/plugins/logs"
"github.com/appbaseio/reactivesearch-api/plugins/telemetry"
)
type chain struct {
middleware.Fifo
}
func (c *chain) Wrap(h http.HandlerFunc) http.HandlerFunc {
return c.Adapt(h, list()...)
}
func list() []middleware.Middleware {
return []middleware.Middleware{
classifyCategory,
logs.Recorder(),
classify.Op(),
classify.Indices(),
auth.BasicAuth(),
validate.Sources(),
validate.Operation(),
validate.Category(),
telemetry.Recorder(),
}
}
func classifyCategory(h http.HandlerFunc) http.HandlerFunc {
return func(w http.ResponseWriter, req *http.Request) {
permissionCategory := category.Permission
ctx := category.NewContext(req.Context(), &permissionCategory)
req = req.WithContext(ctx)
h(w, req)
}
}