protogen

command module
v1.26.0-rc1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 1, 2020 License: MIT Imports: 14 Imported by: 0

README

package protogen

示例

请参考go使用protocolbuffer快速构建API服务demo

初衷

对于"小白"而言, protoc的使用过于烦琐:

  • 熟悉protoc工具
  • 熟悉protoc-gen-go插件
  • 熟悉protoc-gen-go-grpc插件
  • 熟悉protoc-gen-go-http插件

更深入地, 还要了解不同插件依赖protobuf与grpc的版本, 否则出现API引用不一致的场景!

protogen尝试用一个工具解决:

  • 屏敝protoc, protoc-gen-go, protoc-gen-go-grpc与protoc-gen-go-http的使用细节.
  • 屏敝protobuf-go, grpc-go等依赖的版本细节.

一键生成所有代码! 简单明了!

版本

protogen的版本由4部分组成: v--[-path]

  • protoc-gen-go的版本, 例如: v1.25.0
  • protoc-gen-go-grpc的版本, 例如: v1.0.1
  • protoc的版本: 例如: 3.14.0
  • path的版本: 内部版本号

因为protoc-gen-go-http的版本会严格与protoc-gen-go(google.golang.org/protobuf)的版本保持一致! 具体版本信息请执行"protogen --version"查看

扩展

  • 针对pb添加bson(mongo)的自定义tag, 其与json一致, 但没有"omitempty"属性.

其他注意事项

Incompatible change

There is one backward-compatibility breaking change in this version of the tool,which can be disabled with a flag at generation time. 
The Unimplemented<Service>Server struct is now required to be embedded in implementations of the generated <Service>Server interface. 
This requirement guarantees that backward-compatibility is maintained by the generated code when new methods are added to a service, 
which is, itself, a backward-compatible operation.

To disable this behavior, which is recommended only for producing code compatible with earlier generated code, set the flag require_unimplemented_servers=false. For more details, please see the binary's README.md
  • Future-proofing services
By default, to register services using the methods generated by this tool, 
the service implementations must embed the corresponding Unimplemented<ServiceName>Server for future compatibility. 
This is a behavior change from the grpc code generator previously included with protoc-gen-go. 
To restore this behavior, set the option require_unimplemented_servers=false. E.g.:

protoc --go-grpc_out=require_unimplemented_servers=false[,other options...]:. \

Documentation

The Go Gopher

There is no documentation for this package.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL