gRPC以及gRPC Gateway的Golang示例
示例功能:
- gRPC Server
- gRPC Client
- 通过gofast插件生成Golang代码,实现自定义结构体的标签
- gRPC Gateway将JSON与gRPC互相转换
- 自定义gRPC Gateway的错误输出
- 整合zerolog
- 实现方法调用时的Token认证
go get -u github.com/grpc-ecosystem/grpc-gateway/protoc-gen-grpc-gateway
go get -u github.com/golang/protobuf/protoc-gen-go
go get -u github.com/gogo/protobuf/protoc-gen-gofast
在/src/pb
目录中执行以下命令
protoc --proto_path=./ -I $GOPATH/src -I $GOPATH/src/github.com/grpc-ecosystem/grpc-gateway/third_party/googleapis -I $GOPATH/src/github.com/gogo/protobuf/protobuf --gofast_out=plugins=grpc:. *.proto
在/src/pb
目录中执行以下命令
protoc --proto_path=./ -I $GOPATH/src -I $GOPATH/src/github.com/grpc-ecosystem/grpc-gateway/third_party/googleapis --grpc-gateway_out=logtostderr=true:. *.proto