Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/xtlsoft/router
Maybe the best router library in Golang.
https://github.com/xtlsoft/router
Last synced: 2 days ago
JSON representation
Maybe the best router library in Golang.
- Host: GitHub
- URL: https://github.com/xtlsoft/router
- Owner: xtlsoft
- License: mit
- Created: 2018-06-02T12:56:40.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2018-07-19T04:00:50.000Z (over 6 years ago)
- Last Synced: 2024-06-21T07:36:04.797Z (5 months ago)
- Language: Go
- Size: 26.4 KB
- Stars: 8
- Watchers: 2
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Go-Router
[![GoDoc](https://godoc.org/github.com/xtlsoft/router?status.svg)](https://godoc.org/github.com/xtlsoft/router)
Maybe the best router library in Golang.
Designed for all usages. Almost the same as XPHP's router.
## Installation
```bash
go get -u gopkg.in/xtlsoft/router.v1
```## Quickstart
A Simple Example: (In `/examples/01/01.go`)
```go
package mainimport (
"fmt"
router "../.."
)func main() {
r := router.New()
router.AddShortcut("@test", "i[0-9]+");
r.Group("/", func (g *router.Group){
g.On("GET", "test/{test}/{@test:another}", func (req router.Request) router.Response {
return &router.DefaultResponse{
StatusCode: 200,
Body: "Hello World!" + req.(*router.DefaultRequest).RouterVariable["test"],
}
})
g.Any(func (router.Request) router.Response{
return &router.DefaultResponse{
Body: "404 Not Found",
}
})
})fmt.Println( r.Handle("GET", "/test/abc/i234", &router.DefaultRequest{}) )
}
```## Documention
The router is very easy to use.
The document is avaliable in `Document.md`.