https://github.com/nokusukun/cuttle
An extended HTTP router built on top of Echo
https://github.com/nokusukun/cuttle
echo go golang http router
Last synced: 3 months ago
JSON representation
An extended HTTP router built on top of Echo
- Host: GitHub
- URL: https://github.com/nokusukun/cuttle
- Owner: nokusukun
- Created: 2022-02-19T09:47:45.000Z (about 4 years ago)
- Default Branch: master
- Last Pushed: 2022-02-25T05:45:32.000Z (about 4 years ago)
- Last Synced: 2024-06-20T02:07:12.792Z (almost 2 years ago)
- Topics: echo, go, golang, http, router
- Language: Go
- Homepage:
- Size: 53.7 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
---
Cuttle is a heavily opinionated HTTP router in Go.
Its built on top of Echo so almost everything that's not new is most likely from echo.
Note: **Requires Go 1.17**
## Usage
`http://localhost/test?q=hello+world&count=10`
```go
r := cuttle.New()
type testParam struct {
ID uint `bind:"param"`
Query string `bind:"query" as:"q,required"`
Count float64 `bind:"query"`
Token string `bind:"header" as:"X-Security-Token,sensitive"`
}
r.GET("/test/:id", func(params testParam, ctx cuttle.Context) error {
if !validateUser(params.Token) {
return ctx.JSON(401, "unauthorized")
}
return ctx.JSON(200, map[string]interface{}{
"request": params,
"result": fmt.Sprintf("Searched %v on %v", params.Query, params.ID),
})
})
```
It can also be defined as an anonymous function.
```go
r := cuttle.New()
r.GET("/test/:id", func(params struct {
ID uint
Query string
Count float64
Token string `bind:"header" as:"X-Security-Token,sensitive"`
}, ctx cuttle.Context) error {
if !validateUser(params.Token) {
return ctx.JSON(401, "unauthorized")
}
return ctx.JSON(200, map[string]interface{}{
"request": params,
"result": fmt.Sprintf("Searched %v on %v", params.Query, params.ID),
})
})
```
**More examples can be found in `router_test.go`**