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
|
# Path-Router
## What is Path Router
Path Router is a playground for me to test ideas and concept for what I want in a dispatcher.
## What Path Router is not
It's definitely not designed with speed in mind. Stability in the API and design is not done, so things are changing frequently.
## Documentation
### Route
To create a new route, you'll need to create a new Route with the following attributes:
* Method
* Path
* Code
* Validations
or:
&Route{
Method: "GET",
Path: "/blog/{year}/{month}/{day}",
Code: GetArticle,
Validations: map[string]*regexp.Regexp{
"year": regexp.MustCompile("[\\d]{4}"),
"month": regexp.MustCompile("[\\d]{2}"),
"day": regexp.MustCompile("[\\d]{2}"),
},
}
The attribute Validations is optional, but all the keys defined in the map need to be parameters in the URL.
If you use validation, you can write this kind of route with no ambiguity:
&Route{
Method: "GET",
Path: "/user/{id}",
Code: GetUserById,
Validations: map[string]*regexp.Regexp{
"id": regexp.MustCompile("[\\d]+"),
}
}
&Route{
Method: "GET",
Path: "/user/{name}",
Code: GetUserByName,
Validations: map[string]*regexp.Regexp{
"id": regexp.MustCompile("[a-zA-Z]+"),
}
}
## External links
* [![Build Status](https://travis-ci.org/franckcuny/path-router.png?branch=master)](https://travis-ci.org/franckcuny/path-router)
* [Internal Documentation](http://godoc.org/github.com/franckcuny/path-router)
|