eddycjy / go-gin-example

An example of gin
MIT License
6.84k stars 1.59k forks source link

/auth 在路由中已经写成了 POST 方法,但是 swagger 中显示的是 GET #118

Open RussellCao824 opened 4 years ago

RussellCao824 commented 4 years ago

刚下载了代码,发现在swagger页面中调用/auth一直显示 404 page not found。 查看代码发现,在routers/router.go中,/auth路由定义的是POST方法,而swagger页面中显示的是GET方法。 image image 之后,我在postman中使用post方法,带参数请求/auth,还是显示 404 page not foundimage 请问一下,是我使用的姿势不对吗?感谢。

woodyxiong commented 4 years ago

swagger的页面能打开,但是没有一个接口能用的,不知道是不是我操作的问题 所有接口都是参数请求错误

woodyxiong commented 4 years ago

后面仔细看代码,发现是要这样访问的,后续的url都可以这样访问试试

curl --location --request POST 'http://127.0.0.1:8000/auth' \
--form 'username=test' \
--form 'password=test123456'

image

bjk543 commented 3 years ago

同樣的問題,謝謝

caipeishen commented 2 years ago

这个项目标注的swag有点问题

caipeishen commented 2 years ago

刚下载了代码,发现在swagger页面中调用/auth一直显示 404 page not found。 查看代码发现,在routers/router.go中,/auth路由定义的是POST方法,而swagger页面中显示的是GET方法。 image image 之后,我在postman中使用post方法,带参数请求/auth,还是显示 404 page not foundimage 请问一下,是我使用的姿势不对吗?感谢。

post请求,路径是【/auth】

alwaysbetter1314 commented 2 years ago

改下注释,执行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]
dufeng-code commented 2 years ago

修改 swag请求方式 并且如果请求为application/json方式 要修改GetAuth api中参数获取方法c.PostForm改为c.Query

code4happylife commented 2 years ago

request url: http://127.0.0.1:8000/auth with POST body: username:test password:test123 can successfully get token.