-
Notifications
You must be signed in to change notification settings - Fork 0
/
router.go
executable file
·46 lines (35 loc) · 989 Bytes
/
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
// Copyright 2016 Ilya Galimyanov All rights reserved.
// Use of this source code is governed by a MIT style
// license that can be found in the LICENSE file.SE OR OTHER DEALINGS IN THE SOFTWARE.
package socketcrutch
type (
HandlerFunc func(*Session, []byte) error
MiddlewareFunc func(*Session, []byte)
Router struct {
separator string
store RouteStore
RouteGroup
}
RouteStore interface {
Get(string) *Route
Set(string, *Route)
}
)
func newRouter(separator string) *Router {
router := &Router{
store: newRouteStore(),
separator: separator,
}
router.RouteGroup = newRouteGroup("", router, []HandlerFunc{})
return router
}
// SetRouteSeparator sets the character as a separator between the route parts.
func (r *Router) SetRouteSeparator(separator string) {
r.separator = separator
}
func (r *Router) addRoute(path string, route *Route) {
r.store.Set(path, route)
}
func (r *Router) getRoute(path string) *Route {
return r.store.Get(path)
}