-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathroute-methods.go
More file actions
42 lines (33 loc) · 1021 Bytes
/
route-methods.go
File metadata and controls
42 lines (33 loc) · 1021 Bytes
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
package wstf
import (
"net/http"
)
// General method that matches all method.
const MethodAll = "ALL"
func (m *Route) All(processor Processor) *Route {
return m.ListenMethod(MethodAll, processor)
}
func (m *Route) Get(processor Processor) *Route {
return m.ListenMethod(http.MethodGet, processor)
}
func (m *Route) Post(processor Processor) *Route {
return m.ListenMethod(http.MethodPost, processor)
}
func (m *Route) Patch(processor Processor) *Route {
return m.ListenMethod(http.MethodPatch, processor)
}
func (m *Route) Put(processor Processor) *Route {
return m.ListenMethod(http.MethodPut, processor)
}
func (m *Route) Delete(processor Processor) *Route {
return m.ListenMethod(http.MethodDelete, processor)
}
// Add processors to listen specific method.
func (m *Route) ListenMethod(method string, processor Processor) *Route {
if m.Processors[method] == nil {
m.Processors[method] = Processors{processor}
} else {
m.Processors[method] = append(m.Processors[method], processor)
}
return m
}