Skip to content

nokusukun/cuttle

Repository files navigation


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

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.

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

About

An extended HTTP router built on top of Echo

Topics

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages