Hi,I wonder if gin supports custom request method groups? such as Python Flask
@app.route('/login/',methods=['POST','GET'])
or PHP Slim
<?php
$app = new \Slim\Slim();
$app->map('/foo/bar', function() {
echo "I respond to multiple HTTP methods!";
})->via('GET', 'POST');
$app->run();
Thanks.
Comment From: flysnoworg
not support.
Gin has an any
function to set all methods.
But I think it can be supported.
@aveyuan
Comment From: aveyuan
不支持。 杜松子酒具有
any
设置所有方法的功能。但我认为可以得到支持。
@aveyuan
Yes, But any
will register all method.I only want a few of them
Comment From: wangzeping722
不支持。 杜松子酒具有
any
设置所有方法的功能。 但我认为可以得到支持。 @aveyuanYes, But
any
will register all method.I only want a few of them
@aveyuan
I think you can use the any
func, and judge the request method in your method.
Comment From: orov-io
What about this:
loginGroup := service.Group("/login/") // Service is a gin instance...
{
loginGroup.GET("", loginFunc)
loginGroup.POST("", loginFunc)
}
A little verbose, but it will work only for GET and POST...
Comment From: flysnoworg
The following code:
func Handle(r *gin.Engine, httpMethods []string, relativePath string, handlers ...gin.HandlerFunc) gin.IRoutes {
var routes gin.IRoutes
for _, httpMethod := range httpMethods {
routes = r.Handle(httpMethod, relativePath, handlers...)
}
return routes
}
Usage:
Handle(r, []string{"GET", "POST"}, "/", func(c *gin.Context) {
//registers GET and POST Method
})
Comment From: aveyuan
A little verbose, but it will work only for GET and POST...
Use group
httpMethods
Thanks, I think custom request method will be support. @thinkerou
Comment From: BillZong
Use Any() + middleware would be a more elegant solution. But it violate the RESTFul principle, and harder to generate the swagger docs. I think it's time to close this issue, for it's not active any more, and the suggestion is not conventional. @aveyuan