Protobuf3 string validation fails with regex pattern in Go (golang)

164 views Asked by At

I use Go (golang) as my programming language together with Protobuf3 (protoc-gen-validate)to define my PB messages and rpc methods.

Part of my message looks like that:

string xxxxxx = 1 [
    (google.api.field_behavior) = OUTPUT_ONLY,
    (validate.rules).string.pattern = "^[a-zA-Z]{32}$"
  ];

when I try to feed this string

lYcWymElsCfPnJBRGukvLLocTuCCFhgJ

back as a response to an rpc method

return &pb.Zzzzzzz{
        xxxxxxx:         ev.Xxxxx.mehthod() // <--- reflect.TypeOf() == string  value lYcWymElsCfPnJBRGukvLLocTuCCFhgJ,
    }, nil

, I get this error message from the protobuf validation:

embedded message failed validation | caused by: invalid y.x: value does not match regex pattern \"^[a-zA-Z]{32}$\";

I dont see where the prob is! Is there any case that the encoding is different?

0

There are 0 answers