PR #304: Twirp v8 generates code that depends on Protobuf APIv2 (instead of APIv1).
Relevant links
- Protobuf APIv1 repo: https://github.com/golang/protobuf
- Protobuf APIv2 repo: https://github.com/protocolbuffers/protobuf-go
- Protobuf APIv2 release blog post: https://blog.golang.org/protobuf-apiv2
- Twirp version compatibility matrix: https://twitchtv.github.io/twirp/docs/version_matrix.html
Update Instructions
The runtime library github.com/twitchtv/twirp
does not have any changes. The new generated code works with both old and new versions of the runtime library.
Re-generate code with Twirp v8 and Protobuf APIv2:
- Install the new protoc-gen-go plugin:
go install google.golang.org/protobuf/cmd/protoc-gen-go@latest
. - Install the new protoc-gen-twirp plugin:
go install github.com/twitchtv/twirp/protoc-gen-twirp@latest
. - Re-generate code. For example:
protoc --go_out=paths=source_relative:. --twirp_out=paths=source_relative:. service.proto
See Install docs for more information.
Generated clients and services will use the new imports: google.golang.org/protobuf
(APIv2). Projects that make use of the generated clients/servers will have to update their import paths.
The new google.golang.org/protobuf
(APIv2) is mostly backwards compatible, but not completely. You may have to make additional changes to work with the new protobuf library:
- In the proto file, the
option go_package
is mandatory and must include a "/" (it is supposed to be a full import path). If you have to add a full path to the go_package, you may want to generate with the optionspaths=source_relative
. For example:protoc --go_out=. --go_opt=paths=source_relative --twirp_out=. --twirp_opt=paths=source_relative myfile.proto
- Generated message models (structs) now contain a mutex, your linter may complain if the models are copied by value. The solution is to pass pointers instead. Using
reflect.DeepEqual
will not be able to compare protobuf, you can use proto.Equal instead. - Check protobuf go compatibility and their releases for more details.