Skip to content

Commit b913d1e

Browse files
author
Ropon
committed
优化swagger
1 parent ee79f9e commit b913d1e

13 files changed

Lines changed: 303 additions & 266 deletions

File tree

.air.conf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ cmd = "swag init && go build -o tmp/main ."
1212
bin = "tmp/main"
1313
# 自定义的二进制,可以添加额外的编译标识例如添加 GIN_MODE=release
1414
# full_bin = "APP_ENV=dev APP_USER=air ./main"
15-
full_bin = "tmp/main -c conf/work_api.conf"
15+
full_bin = "tmp/main -c conf/work_api.json"
1616
# 监听以下文件扩展名的文件.
1717
include_ext = ["go", "tpl", "tmpl", "html"]
1818
# 忽略这些文件扩展名或目录

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,5 +19,5 @@ config.conf
1919

2020
log
2121
work_api
22-
conf/work_api.conf
22+
conf/work_api.json
2323
tmp

conf/config.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -216,8 +216,8 @@ func Init() (err error) {
216216
if err != nil {
217217
return
218218
}
219-
return nil
220-
//return initMysql()
219+
//return nil
220+
return initMysql()
221221
//return initKafka()
222222
//return initEtcd()
223223

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,13 @@
66
},
77
"MysqlCfg": {
88
"work_api": {
9-
"MysqlConn": "work_api:xxxxx@tcp(127.0.0.1:3306)/work_api?charset=utf8mb4&parseTime=true&loc=Local",
9+
"MysqlConn": "root:ropon.top@tcp(192.168.1.210:3306)/work_api?charset=utf8mb4&parseTime=true&loc=Local",
1010
"MysqlConnectPoolSize": 40
1111
}
1212
},
1313
"RedisSetting": {
1414
"work_api": {
15-
"RedisConn": "db0:6379",
15+
"RedisConn": "192.168.1.210:6379",
1616
"RedisPasswd": "",
1717
"RedisDb": 1
1818
}
@@ -23,7 +23,7 @@
2323
"Key1": "Val1",
2424
"work_api1":"127.0.0.1:2346",
2525
"work_api2":"127.0.0.1:2347",
26-
"JaegerAgentAddr": "xxx:6831"
26+
"JaegerAgentAddr": "192.168.1.210:6831"
2727
},
2828
"ExternalInt64": {
2929
"Key2": 66

controllers/service.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,9 +84,10 @@ func DeleteService(c *gin.Context) {
8484
// @Tags 服务相关接口
8585
// @Accept application/json
8686
// @Produce application/json
87+
// @Param id path uint true "id"
8788
// @Param data body logics.CUServiceReq true "请求参数"
8889
// @Success 200 {object} models.Service "更新成功返回结果"
89-
// @Router /work_api/api/v1/service [put]
90+
// @Router /work_api/api/v1/service/{id} [put]
9091
func UpdateService(c *gin.Context) {
9192
id, flag := checkParamsId(c)
9293
if !flag {
@@ -113,9 +114,10 @@ func UpdateService(c *gin.Context) {
113114
// @Tags 服务相关接口
114115
// @Accept application/json
115116
// @Produce application/json
117+
// @Param id path uint true "id"
116118
// @Param data body logics.ServiceReq true "请求参数"
117119
// @Success 200 {object} models.Service "更新成功返回结果"
118-
// @Router /work_api/api/v1/service [patch]
120+
// @Router /work_api/api/v1/service/{id} [patch]
119121
func PatchUpdateService(c *gin.Context) {
120122
id, flag := checkParamsId(c)
121123
if !flag {
@@ -142,7 +144,7 @@ func PatchUpdateService(c *gin.Context) {
142144
// @Produce application/json
143145
// @Param data query logics.ServiceReq true "请求参数"
144146
// @Success 200 {object} logics.ServiceRes "服务列表返回结果"
145-
// @Router /work_api/api/v1/services [get]
147+
// @Router /work_api/api/v1/service [get]
146148
func GetServices(c *gin.Context) {
147149
req := new(logics.ServiceReq)
148150
if !checkData(c, req) {

docs/docs.go

Lines changed: 101 additions & 89 deletions
Original file line numberDiff line numberDiff line change
@@ -32,34 +32,71 @@ var doc = `{
3232
"basePath": "{{.BasePath}}",
3333
"paths": {
3434
"/work_api/api/v1/service": {
35-
"put": {
36-
"description": "更新服务全部参数接口",
37-
"consumes": [
38-
"application/json"
39-
],
35+
"get": {
36+
"description": "获取服务列表接口",
4037
"produces": [
4138
"application/json"
4239
],
4340
"tags": [
4441
"服务相关接口"
4542
],
46-
"summary": "更新服务全部参数接口",
43+
"summary": "获取服务列表接口",
4744
"parameters": [
4845
{
49-
"description": "请求参数",
50-
"name": "data",
51-
"in": "body",
52-
"required": true,
53-
"schema": {
54-
"$ref": "#/definitions/logics.CUServiceReq"
55-
}
46+
"type": "string",
47+
"description": "服务负责人",
48+
"name": "author_email",
49+
"in": "query"
50+
},
51+
{
52+
"type": "string",
53+
"name": "create_time",
54+
"in": "query"
55+
},
56+
{
57+
"type": "integer",
58+
"name": "id",
59+
"in": "query"
60+
},
61+
{
62+
"type": "integer",
63+
"name": "page_num",
64+
"in": "query"
65+
},
66+
{
67+
"type": "integer",
68+
"name": "page_size",
69+
"in": "query"
70+
},
71+
{
72+
"type": "string",
73+
"description": "服务端口",
74+
"name": "ports",
75+
"in": "query"
76+
},
77+
{
78+
"type": "string",
79+
"description": "服务名称",
80+
"name": "svc_name",
81+
"in": "query"
82+
},
83+
{
84+
"type": "string",
85+
"description": "服务类型",
86+
"name": "svc_type",
87+
"in": "query"
88+
},
89+
{
90+
"type": "string",
91+
"name": "update_time",
92+
"in": "query"
5693
}
5794
],
5895
"responses": {
5996
"200": {
60-
"description": "更新成功返回结果",
97+
"description": "服务列表返回结果",
6198
"schema": {
62-
"$ref": "#/definitions/models.Service"
99+
"$ref": "#/definitions/logics.ServiceRes"
63100
}
64101
}
65102
}
@@ -95,62 +132,69 @@ var doc = `{
95132
}
96133
}
97134
}
98-
},
99-
"patch": {
100-
"description": "更新服务部分参数接口",
101-
"consumes": [
102-
"application/json"
103-
],
135+
}
136+
},
137+
"/work_api/api/v1/service/{id}": {
138+
"get": {
139+
"description": "获取单个服务接口",
104140
"produces": [
105141
"application/json"
106142
],
107143
"tags": [
108144
"服务相关接口"
109145
],
110-
"summary": "更新服务部分参数接口",
146+
"summary": "获取单个服务接口",
111147
"parameters": [
112148
{
113-
"description": "请求参数",
114-
"name": "data",
115-
"in": "body",
116-
"required": true,
117-
"schema": {
118-
"$ref": "#/definitions/logics.ServiceReq"
119-
}
149+
"type": "integer",
150+
"description": "id",
151+
"name": "id",
152+
"in": "path",
153+
"required": true
120154
}
121155
],
122156
"responses": {
123157
"200": {
124-
"description": "更新成功返回结果",
158+
"description": "服务返回结果",
125159
"schema": {
126160
"$ref": "#/definitions/models.Service"
127161
}
128162
}
129163
}
130-
}
131-
},
132-
"/work_api/api/v1/service/{id}": {
133-
"get": {
134-
"description": "获取单个服务接口",
164+
},
165+
"put": {
166+
"description": "更新服务全部参数接口",
167+
"consumes": [
168+
"application/json"
169+
],
135170
"produces": [
136171
"application/json"
137172
],
138173
"tags": [
139174
"服务相关接口"
140175
],
141-
"summary": "获取单个服务接口",
176+
"summary": "更新服务全部参数接口",
142177
"parameters": [
143178
{
144179
"type": "integer",
145180
"description": "id",
146181
"name": "id",
147182
"in": "path",
148183
"required": true
184+
},
185+
{
186+
"description": "请求参数",
187+
"name": "data",
188+
"in": "body",
189+
"required": true,
190+
"schema": {
191+
"$ref": "#/definitions/logics.CUServiceReq"
192+
}
149193
}
150194
],
151195
"responses": {
152196
"200": {
153-
"description": "服务返回结果",
197+
"description": "更新成功返回结果",
154198
"schema": {
155199
"$ref": "#/definitions/models.Service"
156200
}
@@ -180,74 +224,42 @@ var doc = `{
180224
"description": ""
181225
}
182226
}
183-
}
184-
},
185-
"/work_api/api/v1/services": {
186-
"get": {
187-
"description": "获取服务列表接口",
227+
},
228+
"patch": {
229+
"description": "更新服务部分参数接口",
230+
"consumes": [
231+
"application/json"
232+
],
188233
"produces": [
189234
"application/json"
190235
],
191236
"tags": [
192237
"服务相关接口"
193238
],
194-
"summary": "获取服务列表接口",
239+
"summary": "更新服务部分参数接口",
195240
"parameters": [
196-
{
197-
"type": "string",
198-
"description": "服务负责人",
199-
"name": "author_email",
200-
"in": "query"
201-
},
202-
{
203-
"type": "string",
204-
"name": "create_time",
205-
"in": "query"
206-
},
207241
{
208242
"type": "integer",
243+
"description": "id",
209244
"name": "id",
210-
"in": "query"
211-
},
212-
{
213-
"type": "integer",
214-
"name": "page_num",
215-
"in": "query"
216-
},
217-
{
218-
"type": "integer",
219-
"name": "page_size",
220-
"in": "query"
221-
},
222-
{
223-
"type": "string",
224-
"description": "服务端口",
225-
"name": "ports",
226-
"in": "query"
227-
},
228-
{
229-
"type": "string",
230-
"description": "服务名称",
231-
"name": "svc_name",
232-
"in": "query"
233-
},
234-
{
235-
"type": "string",
236-
"description": "服务类型",
237-
"name": "svc_type",
238-
"in": "query"
245+
"in": "path",
246+
"required": true
239247
},
240248
{
241-
"type": "string",
242-
"name": "update_time",
243-
"in": "query"
249+
"description": "请求参数",
250+
"name": "data",
251+
"in": "body",
252+
"required": true,
253+
"schema": {
254+
"$ref": "#/definitions/logics.ServiceReq"
255+
}
244256
}
245257
],
246258
"responses": {
247259
"200": {
248-
"description": "服务列表返回结果",
260+
"description": "更新成功返回结果",
249261
"schema": {
250-
"$ref": "#/definitions/logics.ServiceRes"
262+
"$ref": "#/definitions/models.Service"
251263
}
252264
}
253265
}
@@ -379,7 +391,7 @@ type swaggerInfo struct {
379391
// SwaggerInfo holds exported Swagger Info so clients can modify it
380392
var SwaggerInfo = swaggerInfo{
381393
Version: "1.0",
382-
Host: "work-api.xxx.com",
394+
Host: "work-api.xxx.com:2345",
383395
BasePath: "/",
384396
Schemes: []string{},
385397
Title: "work_api",

0 commit comments

Comments
 (0)