I'm a bit baffled about this. File structure:
/Project
generate.sh
gateway/
cmd/
main.go
pkg/
gatewaypb/
proto/
service.proto
My generate.sh
appears as such:
set -e
module="github.com/my-org/grpc-project"
// Find all dirs with .proto files in them
for proto in */proto; do
dir=$(echo "$proto"|cut -d"/" -f1)
echo "regenerating generated protobuf code for ${proto}"
protoc --proto_path .\
--go-grpc_out=. --go-grpc_opt=module=${module}\
--go_out=. --go_opt=module=${module}\
"${proto}"/*.proto
echo "creating reverse proxy protobuf code for ${proto}"
protoc -I . --grpc-gateway_out=.\
--grpc-gateway_opt logtostderr=true \
--grpc-gateway_opt paths=source_relative \
"${proto}"/*.proto
done
Correctly enough, the first protoc
does as intended, while the second one does not. They output files in different paths when they are supposed to be in the same.
After running generate.sh
, I am left with:
/Project
generate.sh
Service/
cmd/
main.go
pkg/
gatewaypb/
*gateway.pb.go
*gateway._grpc.pb.go
proto/
*gateway.pb.gw.go
service.proto
Why does the generated gateway file end up in the proto/
directory?
What do I need to give as a value to grpc-gateway-out
for it to end up in /pkg/gatewaypb
as the other generated grpc files?
My service.proto
file:
syntax = "proto3";
package gateway.api.v1;
option go_package = "github.com/my-org/grpc-project/gateway/pkg/gatewaypb";
import "google/api/annotations.proto";
message StringMessage {
string value = 1;
}
service YourService {
rpc Echo(StringMessage) returns (StringMessage) {
option (google.api.http) = {
post: "/v1/example/echo"
body: "*"
};
}
}
--grpc-gateway_opt module=${module}
(replacing--grpc-gateway_opt paths=source_relative
). Doing this should mean the same logic is used as the other plugins (more info in this issue). – Brits