Description

Why Gin doesn't have something like this in Echo? https://github.com/labstack/echo/blob/ec92fedf21e817d2d52004a4178292404beb9eaa/group.go#L87 So we can have something like:

func main() {
    g := gin.Default()
    g.Match([]string{"GET", "POST", "PUT"}, "/hello/:name", handlerFunc)
}

Would it be better than this?

func main() {
    g := gin.Default()
    g.GET("/hello/:name", handlerFunc).POST("/hello/:name", handlerFunc).PUT("/hello/:name", handlerFunc)
}

...to prevent ... boilerplate? Thanks,

Comment From: dxgzg

you maybe use g.Any,it support any method.maybe help you

Comment From: KiddoV

@dxgzg gin.Any() will bring all http methods. What if I just want "GET" and "POST" only!!

Comment From: Albert-Gao

easy, just write a high-order function to wrap it, you do not need Gin to support it

Comment From: KiddoV

@Albert-Gao Can I have some code examples?

Comment From: Albert-Gao

Gin Support Two or More Http Methods in One Function?

you can create your own struct wrap the router, and attach the PostAndGet method for a more idiomatic golang experience, but sounds overkill for just a few more helper functions.

@KiddoV

Comment From: KiddoV

Interesting! Thanks!

Comment From: KiddoV

Since we already had .Match() (https://pkg.go.dev/github.com/gin-gonic/gin#RouterGroup.Match). I am closing this issue!