https://github.com/golang/protobuf
https://github.com/grpc/grpc-go
https://grpc.io/docs/quickstart/go/
https://github.com/gogo/protobuf/
使用扩展
https://github.com/gogo/protobuf/blob/master/extensions.md
It works the same as golang/protobuf, simply specify the plugin. Here is an example using gofast:
protoc --gofast_out=plugins=grpc:. my.proto
See https://github.com/gogo/grpc-example for an example of using gRPC with gogoprotobuf and the wider grpc-ecosystem.
https://github.com/envoyproxy/protoc-gen-validate
Go
Go generation should occur into the same output path as the official plugin. For a proto file example.proto, the corresponding validation code is generated into ../generated/example.pb.validate.go:
protoc \
-I . \
-I ${GOPATH}/src \
-I ${GOPATH}/src/github.com/envoyproxy/protoc-gen-validate \
--go_out=":../generated" \
--validate_out="lang=go:../generated" \
example.proto
All messages generated include the new Validate() error method. PGV requires no additional runtime dependencies from the existing generated code.
Gogo
There is an experimental support for gogo protobuf plugin for go. Use the following command to generate gogo-compatible validation code:
protoc \
-I . \
-I ${GOPATH}/src \
-I ${GOPATH}/src/github.com/envoyproxy/protoc-gen-validate \
--gogofast_out=":../generated"\
--validate_out="lang=gogo:../generated" \ example.proto
Gogo support has the following limitations:
only gogofast plugin is supported and tested, meaning that the fields should be properly annotated with gogoproto annotations;
gogoproto.nullable is supported on fields;
gogoproto.stdduration is supported on fields;
gogoproto.stdtime is supported on fields;
https://github.com/grpc-ecosystem/grpc-gateway
“github.com/golang/protobuf/jsonpb”