1
0
mirror of https://github.com/chai2010/advanced-go-programming-book.git synced 2025-05-25 21:52:21 +00:00
2018-12-15 00:26:58 +08:00

79 lines
4.6 KiB
Protocol Buffer
Executable File

// Copyright 2016 Michal Witkowski. All Rights Reserved.
// See LICENSE for licensing terms.
syntax = "proto2";
package validatortest;
import "github.com/gogo/protobuf/gogoproto/gogo.proto";
import "github.com/mwitkow/go-proto-validators/validator.proto";
message ValidatorMessage {
// Embedded message test structure.
message Embedded {
optional string Identifier = 1 [(validator.field) = {regex: "^[a-z]{2,5}$"}];
required int64 SomeValue = 2 [(validator.field) = {int_gt: 0, int_lt: 100}];
}
// String regex constraint tests.
required string StringReq = 1 [(validator.field) = {regex: "^.{2,5}$"}];
required string StringReqNonNull = 2 [(validator.field) = {regex: "^.{2,5}$"}, (gogoproto.nullable) = false];
optional string StringOpt = 3 [(validator.field) = {regex: "^.{2,5}$"}];
optional string StringOptNonNull = 4 [(validator.field) = {regex: "^.{2,5}$"}, (gogoproto.nullable) = false];
required string StringUnescaped = 5 [(validator.field) = {regex: "[\\p{L}\\p{N}]({\\p{L}\\p{N}_- ]{0,28}[\\p{L}\\p{N}])?."}];
// Strict integer inequality constraint tests.
required uint32 IntReq = 6 [(validator.field) = {int_gt: 10}];
required uint32 IntReqNonNull = 7 [(validator.field) = {int_gt: 0}, (gogoproto.nullable) = false];
repeated uint32 IntRep = 8 [(validator.field) = {int_gt: 10}];
repeated uint32 IntRepNonNull = 9 [(validator.field) = {int_gt: 0}];
// Embedded message recursive constraint tests.
required Embedded embeddedReq = 10;
required Embedded embeddedNonNull = 11 [(gogoproto.nullable) = false];
repeated Embedded embeddedRep = 12;
repeated Embedded embeddedRepNonNullable = 13 [(gogoproto.nullable) = false];
// Custom error tests.
optional int32 CustomErrorInt = 16 [(validator.field) = {int_gt: 10, human_error: "My Custom Error"}];
// Strict floating-point inequality constraint tests.
// With this epsilon value, the limits become
// SomeFloat+0.05 > 0.35
// SomeFloat-0.05 < 0.65
required double StrictSomeDoubleReq = 17 [(validator.field) = {float_gt: 0.35, float_lt: 0.65, float_epsilon: 0.05}];
required double StrictSomeDoubleReqNonNull = 18 [(validator.field) = {float_gt: 0.35, float_lt: 0.65, float_epsilon: 0.05}, (gogoproto.nullable) = false];
repeated double StrictSomeDoubleRep = 19 [(validator.field) = {float_gt: 0.35, float_lt: 0.65, float_epsilon: 0.05}];
repeated double StrictSomeDoubleRepNonNull = 20 [(validator.field) = {float_gt: 0.35, float_lt: 0.65, float_epsilon: 0.05}];
required float StrictSomeFloatReq = 21 [(validator.field) = {float_gt: 0.35, float_lt: 0.65, float_epsilon: 0.05}];
required float StrictSomeFloatReqNonNull = 22 [(validator.field) = {float_gt: 0.35, float_lt: 0.65, float_epsilon: 0.05}, (gogoproto.nullable) = false];
repeated float StrictSomeFloatRep = 23 [(validator.field) = {float_gt: 0.35, float_lt: 0.65, float_epsilon: 0.05}];
repeated float StrictSomeFloatRepNonNull = 24 [(validator.field) = {float_gt: 0.35, float_lt: 0.65, float_epsilon: 0.05}];
// Non-strict floating-point inequality constraint tests.
required double SomeDoubleReq = 25 [(validator.field) = {float_gte: 0.25, float_lte: 0.75}];
required double SomeDoubleReqNonNull = 26 [(validator.field) = {float_gte: 0.25, float_lte: 0.75}, (gogoproto.nullable) = false];
repeated double SomeDoubleRep = 27 [(validator.field) = {float_gte: 0.25, float_lte: 0.75}];
repeated double SomeDoubleRepNonNull = 28 [(validator.field) = {float_gte: 0.25, float_lte: 0.75}];
required float SomeFloatReq = 29 [(validator.field) = {float_gte: 0.25, float_lte: 0.75}];
required float SomeFloatReqNonNull = 30 [(validator.field) = {float_gte: 0.25, float_lte: 0.75}, (gogoproto.nullable) = false];
repeated float SomeFloatRep = 31 [(validator.field) = {float_gte: 0.25, float_lte: 0.75}];
repeated float SomeFloatRepNonNull = 32 [(validator.field) = {float_gte: 0.25, float_lte: 0.75}];
// String not-empty constraint tests.
required string SomeNonEmptyString = 33 [(validator.field) = {string_not_empty: true}];
// Repeated base-type without constraint tests.
repeated int32 RepeatedBaseType = 34;
// Repeated element count constraint tests.
repeated int32 Repeated = 35 [(validator.field) = {repeated_count_min: 2, repeated_count_max: 5}];
optional string SomeStringLtReq = 36 [(validator.field) = {length_gt: 2}];
optional string SomeStringGtReq = 37 [(validator.field) = {length_lt: 12}];
optional string SomeStringEqReq = 38 [(validator.field) = {length_eq: 10}];
optional bytes SomeBytesLtReq = 39 [(validator.field) = {length_gt: 5}];
optional bytes SomeBytesGtReq = 40 [(validator.field) = {length_lt: 20}];
optional bytes SomeBytesEqReq = 41 [(validator.field) = {length_eq: 12}];
}