-
Notifications
You must be signed in to change notification settings - Fork 0
/
router.go
63 lines (54 loc) · 1.02 KB
/
router.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
53
54
55
56
57
58
59
60
61
62
63
package internal
type Router map[RoutePath]RouteComponent
func (r Router) Add(method string, path string, handler RequestHandler, handlerComponentID string) {
key := RoutePath{
Method: method,
Path: path,
}
r[key] = RouteComponent{
RequestHandler: handler,
HandlerComponentID: handlerComponentID,
}
}
func (r Router) Remove(method string, path string) {
key := RoutePath{
Method: method,
Path: path,
}
delete(r, key)
}
func (r Router) Get(method string, path string) RequestHandler {
if r == nil {
return nil
}
key := RoutePath{
Method: method,
Path: path,
}
if v, ok := r[key]; ok {
return v.RequestHandler
}
return nil
}
func (r Router) Has(path RoutePath) bool {
if r == nil {
return false
}
if _, ok := r[path]; ok {
return true
}
return false
}
func (r Router) FindHandlerComponentID(method string, path string) string {
if r == nil {
return ""
}
key := RoutePath{
Method: method,
Path: path,
}
if v, ok := r[key]; ok {
return v.HandlerComponentID
}
return ""
}