An open API service indexing awesome lists of open source software.

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

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`**