twitchtv / twirp

A simple RPC framework with protobuf service definitions
https://twitchtv.github.io/twirp/docs/intro.html
Apache License 2.0
7.2k stars 326 forks source link

Can't really use twirp generator with go modules from 1.11 #127

Closed dbudworth closed 6 years ago

dbudworth commented 6 years ago

When using go modules outside the GOPATH, you have to specify the option go_package in your .proto files This is due to having no base directory where your full import path lives, so you have to change your .proto imports to be relative

Once you use relative imports, you have to use option go_package as the google generator will incorrectly guess import path as it really just takes the dir name of the .proto import path

When you specifty the go_package name, google (and twitch) code generators attempt to write the generated .go file to that fully qualified import path, which doesn't work as your project really starts at the repo portion and not the github.com/USER bit

Google generator offers a paths=source_relative option that will write the go file in whatever dir the .proto is in, which is generally what you'd want.

I've submitted #126 to address this It both adds support for the option paths=source_relative, same as go's protoc plugin it also uses the import path declared by option go_package

This isn't directly go module support, but it is needed if your project uses modules.

In the future, proper module support should be added, but I'd hold off until the go team adds module processing to the stdlib as all tooling around it now have to take stuff from vgo's internal packages to even read the custom file format go.mod uses

spenczar commented 6 years ago

I'm closing this as fixed in #126.