protobuf校验规格
syntax = "proto3";
package cmp.rds;
import "google/api/annotations.proto";
import "validate/validate.proto";
import "google/protobuf/any.proto";
option go_package = "api/cmp/rds;rds";
service RdsService {
rpc CreateInstance (CreateInstanceRequest) returns (CreateInstanceResponse) {
option (google.api.http) = {
post: "/rds/v1/createInstance",
body:"*"
};
}
rpc Probe (Request) returns (ProbeResponse) {}
}
message CreateInstanceRequest{
string instanceName=1 [(validate.rules).string.min_len = 1];
string region=2 [(validate.rules).string.min_len = 1];
string zone=3 [(validate.rules).string.min_len = 1];
int32 chargeType=4 [(validate.rules).int32 = {in: [1,2]}];
int32 engine=5 [(validate.rules).int32 = {in: [1]}];
string engineVersion=6 [(validate.rules).string = {in: ['5.7', '8.0']}];
int32 category=7 [(validate.rules).int32 = {in: [1,2]}];
string instanceSpec=8 [(validate.rules).string.min_len = 1];
int32 instanceStorage=9 [(validate.rules).int32 = {lte:8000, gte:20}];
string vpcId=10[(validate.rules).string.min_len = 1];
string subnetId=11[(validate.rules).string.min_len = 1];
string securityIpList=12[(validate.rules).string.min_len = 1];
string accountName=13 [(validate.rules).string.min_len = 1];
string accountPassword=14 [(validate.rules).string.min_len = 1];
string timeZone=15 [(validate.rules).string.min_len = 1];
int32 ignoreCase=16[(validate.rules).int32 = {in: [0,1]}];
int32 usedTime=17;
int32 period=18;
int32 instanceStorageType=19[(validate.rules).int32 = {in: [1,2]}];
int32 instanceNetType=20[(validate.rules).int32 = {in: [1,2]}];
int32 autoUpgradeMinorVersion=21[(validate.rules).int32 = {in: [0,1]}];
}
message CreateInstanceResponse{
int32 code=1;
string requestId=2;
string message=3;
Instance data=4;
message Instance {
string instanceId=1;
}
}
message DeleteInstanceRequest{
string instanceId=1 [(validate.rules).string.min_len = 1];
}
message DeleteInstanceResponse{
int32 code=1;
string requestId=2;
string message=3;
Instance data=4;
message Instance {
string instanceId=1;
}
}
message DescribeZonesRequest {
}
message DescribeZonesResponse{
int32 code=1;
string requestId=2;
string message=3;
ZoneListData data=4;
}
message ZoneListData{
repeated Region regionList = 1;
message Region {
string region=1;
string name=2;
string area=3;
string code=4;
bool isDefault=5;
repeated Zone zones=6;
message Zone {
string zone=1;
string name=2;
bool isDefault=3;
}
}
}
message CreateAccountRequest{
string instanceId=1[(validate.rules).string.min_len=4];
string name=2[(validate.rules).string.min_len=2];
string password=3[(validate.rules).string={
pattern: "^[(0-9)(A-Za-z)(!@#$%^&*()_+-=)]{8,32}$",
}];
int32 kind=4;
string remark=5;
}
message UpdateAccountRequest{
string instanceId=1[(validate.rules).string.min_len=4];
string name=2[(validate.rules).string.min_len=2];
oneof update {
string remark=3[(validate.rules).string.min_len=2];
string password=4[(validate.rules).string={
pattern: "^[(0-9)(A-Za-z)(!@#$%^&*()_+-=)]{8,32}$",
}];
}
}
添加注解
go install github.com/favadi/protoc-go-inject-tag
protoc-go-inject-tag -input="./direct.pb.go"