-
Notifications
You must be signed in to change notification settings - Fork 28
/
dynamic_matching_filter.go
52 lines (43 loc) · 1.03 KB
/
dynamic_matching_filter.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
47
48
49
50
51
52
package web
import (
"net/http"
)
type DynamicMatchingFilter struct {
filters Filters
name string
}
func NewDynamicMatchingFilter(name string) *DynamicMatchingFilter {
return &DynamicMatchingFilter{
name: name,
}
}
func (dmf *DynamicMatchingFilter) AddFilter(dynamicFilter Filter) {
dmf.filters = append(dmf.filters, dynamicFilter)
}
func (dmf *DynamicMatchingFilter) ClearFilters() {
dmf.filters = Filters{}
}
func (dmf *DynamicMatchingFilter) Name() string {
return dmf.name
}
func (dmf *DynamicMatchingFilter) Run(req *Request, next Handler) (*Response, error) {
endpoint := Endpoint{
Method: req.Method,
Path: req.URL.Path,
}
route := Route{
Endpoint: endpoint,
Handler: next.Handle,
}
return dmf.filters.ChainMatching(route).Handle(req)
}
func (dmf *DynamicMatchingFilter) FilterMatchers() []FilterMatcher {
return []FilterMatcher{
{
Matchers: []Matcher{
Path("/**"),
Methods(http.MethodGet, http.MethodPost, http.MethodPut, http.MethodPatch, http.MethodDelete, http.MethodHead),
},
},
}
}