-
Notifications
You must be signed in to change notification settings - Fork 27
/
Copy pathrouter.go
56 lines (51 loc) · 1.42 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
package baa
const (
GET int = iota
POST
PUT
DELETE
PATCH
OPTIONS
HEAD
// RouteLength route table length
RouteLength
)
// RouterMethods declare method key in routeMap
var RouterMethods = map[string]int{
"GET": GET,
"POST": POST,
"PUT": PUT,
"DELETE": DELETE,
"PATCH": PATCH,
"OPTIONS": OPTIONS,
"HEAD": HEAD,
}
// Router is an router interface for baa
type Router interface {
// SetAutoHead sets the value who determines whether add HEAD method automatically
// when GET method is added. Combo router will not be affected by this value.
SetAutoHead(v bool)
// SetAutoTrailingSlash optional trailing slash.
SetAutoTrailingSlash(v bool)
// Match match the route
Match(method, uri string, c *Context) RouteNode
// URLFor use named route return format url
URLFor(name string, args ...interface{}) string
// Add registers a new handle with the given method, pattern and handlers.
Add(method, pattern string, handlers []HandlerFunc) RouteNode
// GroupAdd registers a list of same prefix route
GroupAdd(pattern string, f func(), handlers []HandlerFunc)
}
// RouteNode is an router node
type RouteNode interface {
Name(name string)
Handlers() []HandlerFunc
}
// IsParamChar check the char can used for route params
// a-z->65:90, A-Z->97:122, 0-9->48->57, _->95
func IsParamChar(c byte) bool {
if (c >= 65 && c <= 90) || (c >= 97 && c <= 122) || (c >= 48 && c <= 57) || c == 95 {
return true
}
return false
}