go-gin-example
go-gin-example copied to clipboard
/auth 在路由中已经写成了 POST 方法,但是 swagger 中显示的是 GET
刚下载了代码,发现在swagger页面中调用/auth一直显示 404 page not found
。
查看代码发现,在routers/router.go中,/auth路由定义的是POST方法,而swagger页面中显示的是GET方法。
之后,我在postman中使用post方法,带参数请求/auth,还是显示
404 page not found
。
请问一下,是我使用的姿势不对吗?感谢。
swagger的页面能打开,但是没有一个接口能用的,不知道是不是我操作的问题 所有接口都是参数请求错误
后面仔细看代码,发现是要这样访问的,后续的url都可以这样访问试试
curl --location --request POST 'http://127.0.0.1:8000/auth' \
--form 'username=test' \
--form 'password=test123456'
同樣的問題,謝謝
这个项目标注的swag有点问题
刚下载了代码,发现在swagger页面中调用/auth一直显示
404 page not found
。 查看代码发现,在routers/router.go中,/auth路由定义的是POST方法,而swagger页面中显示的是GET方法。![]()
之后,我在postman中使用post方法,带参数请求/auth,还是显示
404 page not found
。请问一下,是我使用的姿势不对吗?感谢。
post请求,路径是【/auth】
改下注释,执行swag init 现在的auth.go注释确实是get
// @Summary Get Auth
// @Produce json
// @Param username query string true "userName"
// @Param password query string true "password"
// @Success 200 {object} app.Response
// @Failure 500 {object} app.Response
// @Router /auth [get]
修改 swag请求方式 并且如果请求为application/json方式 要修改GetAuth api中参数获取方法c.PostForm改为c.Query
request url: http://127.0.0.1:8000/auth with POST body: username:test password:test123 can successfully get token.