Skip to content

Commit 6046c48

Browse files
committed
feat: request json body
1 parent c69d01c commit 6046c48

File tree

18 files changed

+484
-247
lines changed

18 files changed

+484
-247
lines changed

Makefile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
.PHONY: test
2+
3+
test:
4+
go test ./...

examples/docs/README.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,3 +27,13 @@
2727
4. [菜单管理](./apis-menu.md)
2828

2929
- [获取菜单节点](./apis-menu.md#1-获取菜单节点)
30+
31+
5. [测试示例](./apis-demo.md)
32+
33+
- [struct数组](./apis-demo.md#1-struct数组)
34+
35+
- [int数组](./apis-demo.md#2-int数组)
36+
37+
- [int](./apis-demo.md#3-int)
38+
39+
- [DemoMap](./apis-demo.md#4-DemoMap)

examples/docs/apis-account.md

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22

33
账户相关的接口,含用户注册、登录等
44

5-
1 [用户注册接口](#1-用户注册接口)
6-
2 [用户登录接口](#2-用户登录接口)
5+
1. [用户注册接口](#1-用户注册接口)
6+
2. [用户登录接口](#2-用户登录接口)
77

88
## apis
99

@@ -26,10 +26,19 @@ __password__|_form_|string|true|required||密码
2626
__username__|_form_|string|true|required||用户名
2727
__x-request-id__|_header_|string|false|||request id
2828

29+
_body_:
30+
31+
```javascript
32+
{ //object(handler.RegisterRequest), 注册请求参数
33+
"password": "abc", //string, required, 密码
34+
"username": "abc" //string, required, 用户名
35+
}
36+
```
37+
2938
__Response__:
3039

31-
```json
32-
// StatusCode: 200 注册成功返回数据
40+
```javascript
41+
//StatusCode: 200 注册成功返回数据
3342
{ //object(common.Response), 通用返回结果
3443
"code": 0, //int, 返回状态码
3544
"data": { //object(handler.RegisterResponse), 注册返回数据
@@ -41,8 +50,8 @@ __Response__:
4150
}
4251
```
4352

44-
```json
45-
// StatusCode: 200 密码格式错误
53+
```javascript
54+
//StatusCode: 200 密码格式错误
4655
{ //object(common.Response), 通用返回结果
4756
"code": 10011, //int, 返回状态码
4857
"msg": "password format error", //string, 返回消息
@@ -69,8 +78,8 @@ __validate_code__|_form_|string|false|||验证码
6978

7079
__Response__:
7180

72-
```json
73-
// StatusCode: 200 登录成功返回数据
81+
```javascript
82+
//StatusCode: 200 登录成功返回数据
7483
{ //object(common.Response), 通用返回结果
7584
"code": 0, //int, 返回状态码
7685
"data": { //object(handler.LoginResponse), 登录返回数据
@@ -80,8 +89,8 @@ __Response__:
8089
}
8190
```
8291

83-
```json
84-
// StatusCode: 200 密码错误
92+
```javascript
93+
//StatusCode: 200 密码错误
8594
{ //object(common.Response), 通用返回结果
8695
"code": 10020, //int, 返回状态码
8796
"msg": "password_error", //string, 返回消息

examples/docs/apis-address.md

Lines changed: 24 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22

33
收货地址管理接口
44

5-
1 [添加地址接口](#1-添加地址接口)
6-
2 [更新地址接口](#2-更新地址接口)
7-
3 [删除地址接口](#3-删除地址接口)
8-
4 [获取地址信息](#4-获取地址信息)
9-
5 [获取地址列表](#5-获取地址列表)(Deprecated)
5+
1. [添加地址接口](#1-添加地址接口)
6+
2. [更新地址接口](#2-更新地址接口)
7+
3. [删除地址接口](#3-删除地址接口)
8+
4. [获取地址信息](#4-获取地址信息)
9+
5. [获取地址列表](#5-获取地址列表)(Deprecated)
1010

1111
## apis
1212

@@ -25,10 +25,19 @@ parameter|parameterType|dataType|required|validate|example|description
2525
__address__|_form_|string|true|required||地址
2626
__city_id__|_form_|int64|true|required||城市ID
2727

28+
_body_:
29+
30+
```javascript
31+
{ //object(handler.CreateAddressRequest), 添加地址请求参数
32+
"address": "abc", //string, required, 地址
33+
"city_id": 123 //int64, required, 城市ID
34+
}
35+
```
36+
2837
__Response__:
2938

30-
```json
31-
// StatusCode: 200
39+
```javascript
40+
//StatusCode: 200
3241
{ //object(common.Response), 通用返回结果
3342
"code": 0, //int, 返回状态码
3443
"msg": "success", //string, 返回消息
@@ -54,8 +63,8 @@ __id__|_form_|int64|true|required||地址ID
5463

5564
__Response__:
5665

57-
```json
58-
// StatusCode: 200
66+
```javascript
67+
//StatusCode: 200
5968
{ //object(common.Response), 通用返回结果
6069
"code": 0, //int, 返回状态码
6170
"msg": "success", //string, 返回消息
@@ -80,8 +89,8 @@ __id__|_form_|int64|true|required||地址ID
8089

8190
__Response__:
8291

83-
```json
84-
// StatusCode: 200
92+
```javascript
93+
//StatusCode: 200
8594
{ //object(common.Response), 通用返回结果
8695
"code": 0, //int, 返回状态码
8796
"msg": "success", //string, 返回消息
@@ -106,8 +115,8 @@ __id__|_param_|int64|false|||地址ID
106115

107116
__Response__:
108117

109-
```json
110-
// StatusCode: 200
118+
```javascript
119+
//StatusCode: 200
111120
{ //object(common.Response), 通用返回结果
112121
"code": 0, //int, 返回状态码
113122
"data": { //object(handler.AddressResponse), 返回地址信息
@@ -135,8 +144,8 @@ GET /user/address/list
135144

136145
__Response__:
137146

138-
```json
139-
// StatusCode: 200
147+
```javascript
148+
//StatusCode: 200
140149
{ //object(common.Response), 通用返回结果
141150
"code": 0, //int, 返回状态码
142151
"data": [ //array[handler.AddressResponse]

examples/docs/apis-demo.md

Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
# 测试示例
2+
3+
其它一些示例演示
4+
5+
1. [struct数组](#1-struct数组)
6+
2. [int数组](#2-int数组)
7+
3. [int](#3-int)
8+
4. [DemoMap](#4-DemoMap)
9+
10+
## apis
11+
12+
### 1. struct数组
13+
14+
```text
15+
GET /user/demo/struct_array
16+
```
17+
18+
__Response__:
19+
20+
```javascript
21+
//StatusCode: 200 demo struct array
22+
[ //array[handler.DemoData]
23+
{ //object(handler.DemoData)
24+
"count": 123, //int
25+
"description": "abc", //string
26+
"float_array": [ //array[float64]
27+
1.23
28+
],
29+
"int_array": [ //array[int]
30+
123
31+
],
32+
"int_pointer": 123, //int
33+
"map": { //object(Map)
34+
"abc": 123 //int
35+
},
36+
"object_1": { //object(handler.DemoObject)
37+
"name": "abc" //string
38+
},
39+
"object_2": { //object(handler.DemoObject)
40+
"name": "abc" //string
41+
},
42+
"title": "abc" //string, 标题
43+
}
44+
]
45+
```
46+
47+
---
48+
49+
### 2. int数组
50+
51+
```text
52+
GET /user/demo/int_array
53+
```
54+
55+
__Response__:
56+
57+
```javascript
58+
//StatusCode: 200 demo int array
59+
[ //array[int]
60+
123
61+
]
62+
```
63+
64+
---
65+
66+
### 3. int
67+
68+
```text
69+
GET /user/demo/int
70+
```
71+
72+
__Response__:
73+
74+
```javascript
75+
//StatusCode: 200 demo int
76+
//int
77+
123
78+
```
79+
80+
---
81+
82+
### 4. DemoMap
83+
84+
```text
85+
GET /user/demo/map
86+
```
87+
88+
__Response__:
89+
90+
```javascript
91+
//StatusCode: 200 demo map
92+
{ //object(handler.DemoData)
93+
"abc": { //object(handler.DemoData)
94+
"count": 123, //int
95+
"description": "abc", //string
96+
"float_array": [ //array[float64]
97+
1.23
98+
],
99+
"int_array": [ //array[int]
100+
123
101+
],
102+
"int_pointer": 123, //int
103+
"map": { //object(Map)
104+
"abc": 123 //int
105+
},
106+
"object_1": { //object(handler.DemoObject)
107+
"name": "abc" //string
108+
},
109+
"object_2": { //object(handler.DemoObject)
110+
"name": "abc" //string
111+
},
112+
"title": "abc" //string, 标题
113+
}
114+
}
115+
```
116+
117+
---

examples/docs/apis-menu.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
菜单管理接口
44

5-
1 [获取菜单节点](#1-获取菜单节点)
5+
1. [获取菜单节点](#1-获取菜单节点)
66

77
## apis
88

@@ -18,17 +18,17 @@ GET /user/menu/nodes
1818

1919
__Response__:
2020

21-
```json
22-
// StatusCode: 200
21+
```javascript
22+
//StatusCode: 200
2323
{ //object(common.Response), 通用返回结果
2424
"code": 0, //int, 返回状态码
2525
"data": [ //array[handler.Node]
2626
{ //object(handler.Node)
27-
"id": 123, //int64
28-
"name": "abc", //string
2927
"nodes": [ //array[handler.Node]
3028

31-
]
29+
],
30+
"id": 123, //int64
31+
"name": "abc" //string
3232
}
3333
],
3434
"msg": "success" //string, 返回消息

examples/docs/apis-profile.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
用户资料管理接口
44

5-
1 [获取用户资料](#1-获取用户资料)
5+
1. [获取用户资料](#1-获取用户资料)
66

77
## apis
88

@@ -16,8 +16,8 @@ GET /user/profile/get
1616

1717
__Response__:
1818

19-
```json
20-
// StatusCode: 200
19+
```javascript
20+
//StatusCode: 200
2121
{ //object(common.Response), 通用返回结果
2222
"code": 0, //int, 返回状态码
2323
"data": { //object(handler.ProfileResponse)

examples/svc-user/handler/account.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ func NewAccountHandler() *AccountHandler {
1515
}
1616

1717
type RegisterRequest struct {
18-
Username string `form:"username" validate:"required"` //用户名
19-
Password string `form:"password" validate:"required"` //密码
18+
Username string `form:"username" validate:"required" json:"username,omitempty"` //用户名
19+
Password string `form:"password" validate:"required" json:"password,omitempty"` //密码
2020
} //注册请求参数
2121

2222
type RegisterResponse struct {

examples/svc-user/handler/address.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ func NewAddressHandler() *AddressHandler {
1515
}
1616

1717
type CreateAddressRequest struct {
18-
CityID int64 `form:"city_id" validate:"required"` //城市ID
19-
Address string `form:"address" validate:"required"` //地址
18+
CityID int64 `form:"city_id" validate:"required" json:"city_id,omitempty"` //城市ID
19+
Address string `form:"address" validate:"required" json:"address,omitempty"` //地址
2020
} //添加地址请求参数
2121

2222
//@api POST /address/create

0 commit comments

Comments
 (0)