-
Notifications
You must be signed in to change notification settings - Fork 40
#85: use upside deferring after template generation #86
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
Conversation
| return applyTestTemplate(g.getImplParam(f, s, m, []string{"context", "testing", "github.com/stretchr/testify/require"})) | ||
| func (g *Generator) getTestImpl(s *descriptor.Service, m *descriptor.Method) (string, error) { | ||
| // restore orig GoPkg | ||
| savedPkg := m.RequestType.File.GoPkg |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are you sure that all these vars in the chain m.RequestType.File.GoPkg are being set in all the cases?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, at the moment I'm sure, but I can leave all of params and not to use that chain of a method, as you wish. I think, this part of code needs more complex refactoring, so sometimes it will be reorganized
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was just passing by.
It's up to you, guys.
But maybe it was there for a reason.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This chain being used only inside two functions, each of them is for some (exactly) method generation, so them have to contain *descriptor.Method and as you can see inside handler.go at 393/394 - it refers to m.RequestType.File.GoPkg.Path / m.ResponseType.File.GoPkg.Path without checking all part of the chain
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But maybe it was there for a reason
I don't think so, but I'm waiting for Nick's comment. I think it was there because of time flow %) As this method was implemented for service and for method generation with similar semantics...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A-ha. Yes, everything in that chain must be set (assuming m is not nil), unless there's something seriously wrong with the registry.
I've tried to move to another registry and get rid of hacks like these in #78 - but it seems to be too unstable to do so right away, since we depend a lot on grpc-gateway internals and proto options that mutate them.
I plan to abstract final templates from grpc-gateway internal functions (and refactor this mapfunc mess in the process) first.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's great news!
I got unobvious behavior: there are m.RequestType.File == m.ResponseType.File == f inside getImplParam, so I use just pointer to file from method to prevent some kind of magic magic...