Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

A question about generating file protoc-gen-grpc-gateway/gengateway/template.go #864

Closed
DaHuMao opened this issue Feb 11, 2019 · 10 comments
Closed

Comments

@DaHuMao
Copy link

DaHuMao commented Feb 11, 2019

Hello:
I am a rookie. I have a question. When I modified the template.go file in the github.com/grpc-ecosystem/grpc-gateway/protoc-gen-grpc-gateway/gengateway/ directory, the *.pb.gw.go file did not change.
Looking forward to your reply!

@DaHuMao DaHuMao changed the title A problem about template.go A question about generating file protoc-gen-grpc-gateway/gengateway/template.go Feb 11, 2019
@achew22
Copy link
Collaborator

achew22 commented Feb 11, 2019

@DaHuMao, per the issue template, can you please document the steps that you have tried to alleviate your problem?

@DaHuMao
Copy link
Author

DaHuMao commented Feb 11, 2019

@achew22 I need to insert some custom code into the *.pb.gw.go, but I don't want to have to modify it every time I generate a *.pb.gw.go file, so I tried to modify the generated template file in gprc-gateway: template.go.After the modification, I generated the *.pb.gw.go file again. I found that template.go was not called at all when the file was generated。Is the generated template not the template.go file in the github.com/grpc-ecosystem/grpc-gateway/protoc-gen-grpc-gateway/gengateway/ directory?

@johanbrandhorst
Copy link
Collaborator

@DaHuMao did you reinstall the generator after changing the template file? If there's something you want changed about the generated file, why not raise an issue and make a pull request, maybe everyone who uses this project could use it?

@DaHuMao
Copy link
Author

DaHuMao commented Feb 11, 2019

@johanbrandhorst I am just a rookie ,who just starting to learn this aspect.
I want to change the build template because of the specific requirements of the project. Do you mean i should reinstall protobuf if i want to change it.

@DaHuMao
Copy link
Author

DaHuMao commented Feb 11, 2019

@johanbrandhorst I had reinstalled protobuf ,but i did not work

@johanbrandhorst
Copy link
Collaborator

I mean protoc-gen-grpc-gateway, not protoc. After changing the template you need to run go install ./protoc-gen-grpc-gateway from the root of this repo. That should fix your problem.

@johanbrandhorst
Copy link
Collaborator

I'm going to close this as it's not really an issue related to the repo. Please join the slack channel if you need more direct assistance.

@DaHuMao
Copy link
Author

DaHuMao commented Feb 11, 2019

@johanbrandhorst OK,Thank you very much!

@yugui
Copy link
Member

yugui commented Feb 16, 2019

@DaHuMao
I did not expect users would need to modify template.go when I wrote it. If you do, obviously you need to rebuild protoc-gen-grpc-gateway itself, reinstall it and then you need to regenerate your codes.

But before trying directly modifying template.go, please take a look at https://grpc-ecosystem.github.io/grpc-gateway/docs/customizingyourgateway.html. It might give a better solution.
Also please note that you don't need to modify the generated code if you just need to add some methods and/or variables into the package. Golang allows you to simply add another hand-written .go file into the same package.

@DaHuMao
Copy link
Author

DaHuMao commented Feb 18, 2019

@yugui Thank you for your advice. But i want to handle the error and the message in *.pb.gw.go,befor they passed into the client function,not just add some function to *.pb.gw.go

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants