- 一、用戶表SQL
- 二、proto3檔案定義如下:
- 三、proto檔案欄位對應的Json資料格式
- 1、InfoRequest
- 2、InfoResponse
- 3、ListRequest
- 4、ListResponse
- 5、ListAllResponse
- 6、EditRequest
- 7、EditResponse
一、用戶表SQL
- 用戶表sql如下:
CREATE TABLE `user` (
`id` int(11) NOT NULL COMMENT '主鍵ID',
`name` varchar(100) DEFAULT NULL COMMENT '用戶名',
`password` varchar(100) DEFAULT NULL COMMENT '用戶密碼',
`balance` decimal(10,2) DEFAULT NULL COMMENT '用戶余額',
`status` tinyint(1) DEFAULT NULL COMMENT '用戶狀態:0-待審核;1-已審核',
`create_time` int(10) DEFAULT NULL COMMENT '創建時間',
`update_time` int(10) DEFAULT NULL COMMENT '更新時間',
`is_deleted` tinyint(1) DEFAULT NULL COMMENT '是否洗掉:1-是;0-否',
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
二、proto3檔案定義如下:
syntax = "proto3";
package user;
option go_package = "shop/proto/user;user";
service UserService {
rpc Info(InfoRequest) returns (InfoResponse) {} //單條資料獲取
rpc List(ListRequest) returns (ListResponse) {} //分頁資料獲取
rpc ListAll(ListRequest) returns (ListAllResponse) {} //所有資料獲取
rpc Edit(EditRequest) returns (EditResponse) {} //編輯用戶資料
}
//定義單條資料請求、回應資料
message InfoRequest {
int64 id = 1;
}
message InfoResponse {
int64 id = 1;
string name = 2;
string password = 3;
double balance = 4;
int64 status = 5;
int64 create_time = 6;
int64 update_time = 7;
int64 is_deleted = 8;
}
//定義分頁資料請求、回應資料
message ListRequest {
int64 id = 1;
repeated int64 ids = 2;
string name = 3;
int64 page = 4;
int64 page_size = 5;
repeated string fields = 6;
map<string, string> sorter = 7;
}
message ListResponse {
int64 count = 1;
repeated InfoResponse data = 2;
}
//定義所有資料請求、回應資料
message ListAllResponse {
repeated InfoResponse list = 1;
}
//用戶編輯資料請求、回應資料
message EditRequest {
InfoResponse data = 1;
repeated string fields = 2;
}
message EditResponse {
bool res = 1;
}
三、proto檔案欄位對應的Json資料格式
1、InfoRequest
{
"id": 1
}
2、InfoResponse
{
"id": 1,
"name": "姓名",
"password": "$2y$10$G\/oxMamAVl.CPpE4MIeppujopq51TjM0hH0VV4oInrAKTti7nblAy",
"balance": 0.01,
"status": 1,
"create_time": 1612669219,
"update_time": 1612669219,
"is_delete": 0
}
3、ListRequest
{
"id": 1,
"ids": [1, 2, 3],
"name": "姓名",
"page": 1,
"page_size": 10,
"fields": ["id", "name", "balance", "status"],
"sorter": {
"create_time": "DESC",
"id": "ASC"
}
}
4、ListResponse
{
"count": 2,
"data": [{
"id": 1,
"name": "姓名",
"password": "$2y$10$G\/oxMamAVl.CPpE4MIeppujopq51TjM0hH0VV4oInrAKTti7nblAy",
"balance": 0.01,
"status": 1,
"create_time": 1612669219,
"update_time": 1612669219,
"is_delete": 0
}, {
"id": 1,
"name": "姓名",
"password": "$2y$10$G\/oxMamAVl.CPpE4MIeppujopq51TjM0hH0VV4oInrAKTti7nblAy",
"balance": 0.01,
"status": 1,
"create_time": 1612669219,
"update_time": 1612669219,
"is_delete": 0
}]
}
5、ListAllResponse
{
"list": [{
"id": 1,
"name": "姓名",
"password": "$2y$10$G\/oxMamAVl.CPpE4MIeppujopq51TjM0hH0VV4oInrAKTti7nblAy",
"balance": 0.01,
"status": 1,
"create_time": 1612669219,
"update_time": 1612669219,
"is_delete": 0
}, {
"id": 1,
"name": "姓名",
"password": "$2y$10$G\/oxMamAVl.CPpE4MIeppujopq51TjM0hH0VV4oInrAKTti7nblAy",
"balance": 0.01,
"status": 1,
"create_time": 1612669219,
"update_time": 1612669219,
"is_delete": 0
}]
}
6、EditRequest
{
"data": {
"id": 1,
"name": "姓名",
"password": "$2y$10$G\/oxMamAVl.CPpE4MIeppujopq51TjM0hH0VV4oInrAKTti7nblAy",
"balance": 0.01,
"status": 1,
"create_time": 1612669219,
"update_time": 1612669219,
"is_delete": 0
},
"fields": ["id", "name", "balance", "status"]
}
7、EditResponse
{
"res": true
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/257767.html
標籤:其他
上一篇:資料分析模型 第八章
下一篇:一致性Hash演算法
