https://github.com/tomocy/route
https://github.com/tomocy/route
golang routing
Last synced: 12 days ago
JSON representation
- Host: GitHub
- URL: https://github.com/tomocy/route
- Owner: tomocy
- License: mit
- Created: 2019-04-26T05:51:14.000Z (almost 7 years ago)
- Default Branch: master
- Last Pushed: 2019-05-02T15:36:08.000Z (over 6 years ago)
- Last Synced: 2024-06-21T14:24:03.476Z (over 1 year ago)
- Topics: golang, routing
- Language: Go
- Size: 7.81 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Route
[](https://circleci.com/gh/tomocy/route)
[](https://opensource.org/licenses/MIT)
route manager
## Installation
```
go get github.com/tomocy/route
```
## Useage
Map routes
```go
package route
import (
// ...
)
func MapRoutes() {
Web.Map(webRaw)
API.Map(apiRaw)
}
var (
Web = make(route.RouteMap)
API = make(route.RouteMap)
)
var (
webRaw = route.RawMap{
"user.index": "http://localhost/users",
"user.new": "http://localhost/users/new",
"user.create": "http://localhost/users",
}
apiRaw = route.RawMap{
"user.index": "http://localhost/api/users/index",
}
)
```
`(RouteMap).Route(string)` returns `*url.URL`
```go
http.HandlerFunc(route.Web.Route("user.new").Path, func(w http.ResponseWriter, r *http.Request) {
// handle user.new
})
http.HandlerFunc(route.Web.Route("user.create").Path, {
// handle user.create
// after creating a user
http.Redirect(w, r, route.Web.Route("user.index").String(), http.StatusSeeOther)
})
```
## Author
[tomocy](https://github.com/tomocy)