Skip to content

Commit 7ed43e1

Browse files
author
Ropon
committed
fix: swag
1 parent 7ecd0a0 commit 7ed43e1

11 files changed

Lines changed: 100 additions & 137 deletions

File tree

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ bash new_project.sh testpro 8866
2020
#### 3、dev
2121

2222
```shell
23+
#热加载自动生成swagger文档
24+
go install github.com/swaggo/swag/cmd/swag@v1.8.12
2325
cd testpro
2426
./air
2527
```

controllers/hi.go

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,37 @@
11
package controllers
22

33
import (
4+
"fmt"
45
"github.com/gin-gonic/gin"
56
"github.com/ropon/work_api/utils"
7+
"strconv"
68
"time"
79
)
810

11+
func initExtraKeys(c *gin.Context) (string, string) {
12+
return c.Request.Header.Get("user_email"), c.Request.Header.Get("ops_admin")
13+
}
14+
15+
//检查params id
16+
func checkParamsId(c *gin.Context) (uint, bool) {
17+
idStr := c.Param("id")
18+
id, err := strconv.Atoi(idStr)
19+
if err != nil || id == 0 {
20+
utils.GinErrRsp(c, utils.ErrCodeParamInvalid, fmt.Sprintf("传入id[%s]不合法", idStr))
21+
return 0, false
22+
}
23+
return uint(id), true
24+
}
25+
26+
//检查请求体
27+
func checkData(c *gin.Context, v interface{}) bool {
28+
if err := c.ShouldBind(v); err != nil {
29+
utils.GinErrRsp(c, utils.ErrCodeParamInvalid, "参数有误:"+err.Error())
30+
return false
31+
}
32+
return true
33+
}
34+
935
func Hi(c *gin.Context) {
1036
time.Sleep(time.Second * 10)
1137
utils.GinOKRsp(c, "hi ropon", "ok")

controllers/service.go

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,11 @@
11
package controllers
22

33
import (
4-
"fmt"
54
"github.com/gin-gonic/gin"
65
"github.com/ropon/work_api/logics"
76
"github.com/ropon/work_api/utils"
8-
"strconv"
97
)
108

11-
func initExtraKeys(c *gin.Context) (string, string) {
12-
return c.Request.Header.Get("user_email"), c.Request.Header.Get("ops_admin")
13-
}
14-
15-
//检查params id
16-
func checkParamsId(c *gin.Context) (uint, bool) {
17-
idStr := c.Param("id")
18-
id, err := strconv.Atoi(idStr)
19-
if err != nil || id == 0 {
20-
utils.GinErrRsp(c, utils.ErrCodeParamInvalid, fmt.Sprintf("传入id[%s]不合法", idStr))
21-
return 0, false
22-
}
23-
return uint(id), true
24-
}
25-
26-
//检查请求体
27-
func checkData(c *gin.Context, v interface{}) bool {
28-
if err := c.ShouldBind(v); err != nil {
29-
utils.GinErrRsp(c, utils.ErrCodeParamInvalid, "参数有误:"+err.Error())
30-
return false
31-
}
32-
return true
33-
}
34-
359
// CreateService 创建服务接口
3610
// @Summary 创建服务接口
3711
// @Description 创建服务接口

docs/docs.go

Lines changed: 17 additions & 60 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/swagger.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@
207207
],
208208
"responses": {
209209
"200": {
210-
"description": ""
210+
"description": "OK"
211211
}
212212
}
213213
},

docs/swagger.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ paths:
167167
- application/json
168168
responses:
169169
"200":
170-
description: ""
170+
description: OK
171171
summary: 删除服务接口
172172
tags:
173173
- 服务相关接口

go.mod

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,22 +7,18 @@ require (
77
github.com/Shopify/sarama v1.30.1
88
github.com/gin-contrib/pprof v1.3.0
99
github.com/gin-gonic/gin v1.7.4
10-
github.com/go-openapi/spec v0.20.4 // indirect
1110
github.com/go-playground/validator/v10 v10.9.0 // indirect
1211
github.com/go-redis/redis v0.0.0-20190803144825-742f3ccb21cd
1312
github.com/go-sql-driver/mysql v1.6.1-0.20210825083250-6cf3092b0e12
1413
github.com/jinzhu/gorm v1.9.17-0.20210521233931-90f139aba3a6
1514
github.com/mailru/easyjson v0.7.7 // indirect
1615
github.com/mattn/go-isatty v0.0.13 // indirect
1716
github.com/opentracing/opentracing-go v1.2.0
18-
github.com/ropon/logger v1.0.1
17+
github.com/ropon/logger v1.0.2
1918
github.com/swaggo/gin-swagger v1.3.3
20-
github.com/swaggo/swag v1.7.6
19+
github.com/swaggo/swag v1.16.1
2120
github.com/uber/jaeger-client-go v2.30.0+incompatible
2221
github.com/uber/jaeger-lib v2.4.1+incompatible // indirect
2322
go.etcd.io/etcd/client/v3 v3.5.1
24-
golang.org/x/net v0.0.0-20211216030914-fe4d6282115f // indirect
25-
golang.org/x/sys v0.0.0-20211216021012-1d35b9e2eb4e // indirect
26-
golang.org/x/tools v0.1.8 // indirect
2723
google.golang.org/protobuf v1.27.1 // indirect
2824
)

0 commit comments

Comments
 (0)