mirror of
https://github.com/zhufuyi/sponge.git
synced 2025-10-17 22:30:46 +08:00
190 lines
5.6 KiB
Protocol Buffer
190 lines
5.6 KiB
Protocol Buffer
// todo generate the protobuf code here
|
||
// delete the templates code start
|
||
|
||
syntax = "proto3";
|
||
|
||
package api.serverNameExample.v1;
|
||
|
||
import "validate/validate.proto";
|
||
import "api/types/types.proto";
|
||
import "google/api/annotations.proto";
|
||
import "protoc-gen-openapiv2/options/annotations.proto";
|
||
import "tagger/tagger.proto";
|
||
|
||
option go_package = "github.com/zhufuyi/sponge/api/serverNameExample/v1;v1";
|
||
|
||
// 生成*.swagger.json文档的默认设置
|
||
option (grpc.gateway.protoc_gen_openapiv2.options.openapiv2_swagger) = {
|
||
host: "localhost:8080"
|
||
base_path: ""
|
||
info: {
|
||
title: "serverNameExample api docs";
|
||
version: "v0.0.0";
|
||
};
|
||
schemes: HTTP;
|
||
schemes: HTTPS;
|
||
consumes: "application/json";
|
||
produces: "application/json";
|
||
};
|
||
|
||
service userExampleService {
|
||
rpc Create(CreateUserExampleRequest) returns (CreateUserExampleReply) {
|
||
option (google.api.http) = {
|
||
post: "/api/v1/userExample"
|
||
body: "*"
|
||
};
|
||
option (grpc.gateway.protoc_gen_openapiv2.options.openapiv2_operation) = {
|
||
summary: "创建userExample",
|
||
description: "提交信息创建userExample",
|
||
tags: "userExample",
|
||
};
|
||
}
|
||
|
||
rpc DeleteByID(DeleteUserExampleByIDRequest) returns (DeleteUserExampleByIDReply) {
|
||
option (google.api.http) = {
|
||
delete: "/api/v1/userExample/{id}"
|
||
};
|
||
option (grpc.gateway.protoc_gen_openapiv2.options.openapiv2_operation) = {
|
||
summary: "删除userExample",
|
||
description: "根据id删除userExample",
|
||
tags: "userExample",
|
||
};
|
||
}
|
||
|
||
rpc UpdateByID(UpdateUserExampleByIDRequest) returns (UpdateUserExampleByIDReply) {
|
||
option (google.api.http) = {
|
||
put: "/api/v1/userExample/{id}"
|
||
body: "*"
|
||
};
|
||
option (grpc.gateway.protoc_gen_openapiv2.options.openapiv2_operation) = {
|
||
summary: "更新userExample信息",
|
||
description: "根据id更新userExample信息",
|
||
tags: "userExample",
|
||
};
|
||
}
|
||
|
||
rpc GetByID(GetUserExampleByIDRequest) returns (GetUserExampleByIDReply) {
|
||
option (google.api.http) = {
|
||
get: "/api/v1/userExample/{id}"
|
||
};
|
||
option (grpc.gateway.protoc_gen_openapiv2.options.openapiv2_operation) = {
|
||
summary: "获取userExample详情",
|
||
description: "根据id获取userExample详情",
|
||
tags: "userExample",
|
||
};
|
||
}
|
||
|
||
rpc ListByIDs(ListUserExampleByIDsRequest) returns (ListUserExampleByIDsReply) {
|
||
option (google.api.http) = {
|
||
post: "/api/v1/userExamples/ids"
|
||
body: "*"
|
||
};
|
||
option (grpc.gateway.protoc_gen_openapiv2.options.openapiv2_operation) = {
|
||
summary: "根据多个id获取userExample列表",
|
||
description: "使用post请求,根据多个id获取userExample列表",
|
||
tags: "userExample",
|
||
};
|
||
}
|
||
|
||
rpc List(ListUserExampleRequest) returns (ListUserExampleReply) {
|
||
option (google.api.http) = {
|
||
post: "/api/v1/userExamples"
|
||
body: "*"
|
||
};
|
||
option (grpc.gateway.protoc_gen_openapiv2.options.openapiv2_operation) = {
|
||
summary: "获取userExample列表",
|
||
description: "使用post请求获取userExample列表",
|
||
tags: "userExample",
|
||
};
|
||
}
|
||
}
|
||
|
||
enum GenderType {
|
||
UNKNOWN = 0;
|
||
MALE = 1;
|
||
FEMALE = 2;
|
||
};
|
||
|
||
// 如果使用grpc gateway,建议例外添加target,请求时可以自动校验,
|
||
// 例如 string email = 2 [(tagger.tags) = "binding:\"email\"" ];
|
||
|
||
message CreateUserExampleRequest {
|
||
string name = 1 [(validate.rules).string.min_len = 2]; // 名称
|
||
string email = 2 [(validate.rules).string.email = true]; // 邮件
|
||
string password = 3 [(validate.rules).string.min_len = 10]; // 密码
|
||
string phone=4 [(validate.rules).string = {pattern: "^1[3456789]\\d{9}$"}]; // 手机号码
|
||
string avatar=5 [(validate.rules).string.uri = true]; // 头像
|
||
int32 age=6 [(validate.rules).int32 = {gte:0, lte: 120}]; // 年龄
|
||
GenderType gender=7 [(validate.rules).enum.defined_only = true]; // 性别,0:未知,1:男,2:女
|
||
}
|
||
|
||
message CreateUserExampleReply {
|
||
uint64 id = 1 [(validate.rules).uint64.gte = 1];
|
||
}
|
||
|
||
message DeleteUserExampleByIDRequest {
|
||
uint64 id = 1 [(validate.rules).uint64.gte = 1, (tagger.tags) = "uri:\"id\"" ];
|
||
}
|
||
|
||
message DeleteUserExampleByIDReply {
|
||
|
||
}
|
||
|
||
message UpdateUserExampleByIDRequest {
|
||
uint64 id = 1 [(validate.rules).uint64.gte = 1 , (tagger.tags) = "uri:\"id\"" ];
|
||
string name = 2; // 名称
|
||
string email = 3; // 邮件
|
||
string password = 4; // 密码
|
||
string phone=5; // 手机号码
|
||
string avatar=6; // 头像
|
||
int32 age=7; // 年龄
|
||
GenderType gender=8; // 性别,1:男,2:女
|
||
int32 status=9; // 账号状态
|
||
int64 login_at=10; // 登录时间戳
|
||
}
|
||
|
||
message UpdateUserExampleByIDReply {
|
||
|
||
}
|
||
|
||
message UserExample {
|
||
uint64 id = 1;
|
||
string name = 2; // 名称
|
||
string email = 3; // 邮件
|
||
string phone=4; // 手机号码
|
||
string avatar=5; // 头像
|
||
int32 age=6; // 年龄
|
||
GenderType gender=7; // 性别,1:男,2:女
|
||
int32 status=8; // 账号状态
|
||
int64 login_at=9; // 登录时间戳
|
||
int64 created_at=10; // 创建时间
|
||
int64 updated_at=11; // 更新时间
|
||
}
|
||
|
||
message GetUserExampleByIDRequest {
|
||
uint64 id = 1 [(validate.rules).uint64.gte = 1, (tagger.tags) = "uri:\"id\"" ];
|
||
}
|
||
|
||
message GetUserExampleByIDReply {
|
||
UserExample userExample = 1;
|
||
}
|
||
|
||
message ListUserExampleByIDsRequest {
|
||
repeated uint64 ids = 1;
|
||
}
|
||
|
||
message ListUserExampleByIDsReply {
|
||
repeated UserExample userExamples = 1;
|
||
}
|
||
|
||
message ListUserExampleRequest {
|
||
types.Params params = 1 [(validate.rules).message.required = true];
|
||
}
|
||
|
||
message ListUserExampleReply {
|
||
int64 total =1;
|
||
repeated UserExample userExamples = 2;
|
||
}
|
||
|
||
// delete the templates code end
|