golang grpc以及gateway

标准protobbuf

https://github.com/golang/protobuf

标准grpc

https://github.com/grpc/grpc-go
https://grpc.io/docs/quickstart/go/

go语言增强的gogoprotobuf

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.

字段validate

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;

grpc gateway

https://github.com/grpc-ecosystem/grpc-gateway

json pb互相转换

“github.com/golang/protobuf/jsonpb”

发布了96 篇原创文章 · 获赞 0 · 访问量 1028

猜你喜欢

转载自blog.csdn.net/weixin_45594127/article/details/103712949