安装
go get -u github.com/envoyproxy/protoc-gen-validate
使用方法:float order_money = 4[(validate.rules).float.gt = 1];
message OrderMain {
int32 order_id = 1;
string order_no = 2;
int32 user_id = 3;
float order_money = 4[(validate.rules).float.gt = 1];
google.protobuf.Timestamp order_time = 5;
repeated OrderDetail order_details = 6;
}
服务端验证
err := request.OrderMain.Validate()
if err != nil {
return &OrderResponse{
Status: "failed",
Message: err.Error(),
}, nil
}