moul / protoc-gen-gotemplate

:open_file_folder: generic protocol generator based on golang's text/template (grpc/protobuf)
https://manfred.life/protoc-gen-gotemplate
MIT License
438 stars 70 forks source link

Support grpc custom option #79

Closed gigimushroom closed 6 years ago

gigimushroom commented 6 years ago

option (google.api.http) = { post: "/v1/example/echo_body" body: "*" };

It will output errors: example.proto:32:14: Option "(google.api.http)" unknown.

Is there a workaround?

weitzj commented 6 years ago

You need to import it:

# Go to your model directory and 
mkdir -p google/api/

# Download the http.proto https://github.com/googleapis/googleapis/tree/master/google/api 
curl -L 'https://raw.githubusercontent.com/googleapis/googleapis/master/google/api/http.proto' > google/api/http.proto

# Run protoc again

If this still does not work, you might have to add another protoc --proto-path pointing to the google directory

gigimushroom commented 6 years ago

It seems I got errors when using "destination_dir":

protoc --gotemplate_out=debug=false,template_dir=./greeter_server/templates/,destination_dir:./greeter_server protos/proxy.proto 2017/12/14 14:19:27 Err: invalid parameter: "destination_dir"

weitzj commented 6 years ago

Sorry, I can't follow how these errors are related

gigimushroom commented 6 years ago

Is there a way to feed 2 proto files together? My proto file A import another file B, if I just run this tool for A, I got "some type" is not defined.

gigimushroom commented 6 years ago

Ok, I figured it out: protoc -I protos/ --gotemplate_out=debug=false,template_dir=greeter_server/templates,destination_dir=greeter_server:greeter_server protos/xxx.proto