Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@wish-master
Copy link

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...

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
Copy link
Contributor

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?

Copy link
Author

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

Copy link
Contributor

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.

Copy link
Author

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

Copy link
Author

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...

Copy link
Owner

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.

Copy link
Author

@wish-master wish-master Apr 5, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's great news!

@utrack utrack merged commit d57b4ad into utrack:master Apr 5, 2020
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

Successfully merging this pull request may close these issues.

3 participants