-
Notifications
You must be signed in to change notification settings - Fork 0
/
route.go
47 lines (39 loc) · 907 Bytes
/
route.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
package router
import "strings"
// Route holds Route information.
type Route struct {
method string
path string
name string
stack []Handler
}
// Method returns route method.
func (r *Route) Method() string {
return r.method
}
// Path returns route method.
func (r *Route) Path() string {
return r.path
}
// Name returns route method.
func (r *Route) Name() string {
return r.name
}
// SetName sets/updates route name.
func (r *Route) SetName(name string) {
r.name = name
}
// URL generate URL from route path with given parameters.
func (r *Route) URL(parameters map[string]string) string {
uri := r.path
if parameters != nil {
for name, value := range parameters {
uri = strings.Replace(uri, ":"+name, value, 1)
}
}
return uri
}
// newRoute creates a new Route instance.
func newRoute(method, path string, stack []Handler) *Route {
return &Route{method, path, "", stack}
}