-
Notifications
You must be signed in to change notification settings - Fork 207
Implement Service Method Generation Control #158
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
Allow users to specify which methods they would like to generate for a gRPC service.
|
Hey @JeremyV2014, A few things: Define the method enums with How about making the API: // only render Get and Delete
entproto.Service(
entproto.Methods(entproto.MethodGet | entproto.MethodDelete)
)
// render all
entproto.Service(
entproto.Methods(entproto.MethodAll)
)
// default behavior equivalent to MethodAll
// to make this work you will need to use the functional options pattern
entproto.Service() |
entproto/service.go
Outdated
|
|
||
| func Service() schema.Annotation { | ||
| return service{Generate: true} | ||
| func Service(methods ...Method) schema.Annotation { |
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.
should be a functional option. think that we may want other parameters. in other words
entproto.Service(entproto.MethodAll) should not work.
if you're not familiar with the concept see this post its pretty cool:
https://dave.cheney.net/2014/10/17/functional-options-for-friendly-apis
and see the implementation in a file right next to you: https://github.com/ent/contrib/blob/master/entproto/message.go#L28-L40
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.
Thanks! I'll work on incorporating this into my PR. I also didn't realize I could do bit shifts with iota. Very cool!
If it wasn't clear, I'm still relatively new to Go; I'm still learning some of the design patterns for it.
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.
You're doing great! Thanks for being patient and pushing this through!
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.
Okay, I think I've implemented this design pattern appropriately now. It is definitely quite neat!
|
The implementation looks right, thanks! Please add tests? https://github.com/ent/contrib/tree/master/entproto#contributing |
To internal/entprototest/service_test.go? |
rotemtam
left a comment
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.
Added some final comments.
Also if you can, please update the README file for entproto (in a separate PR is fine) and update the gRPC documentation on the ent site (also in a separate PR).
rotemtam
left a comment
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.
Also notice that CI is failing
Looks like I'm missing copyright headers in the new files. |
Should entproto.Service() get a higher header level? It seems like this is quite a bit of information to add to that section.
How would you like this introduced on the website? Are you thinking of a new page discussing method generation options for services? I could walk through modifying the User service to generate only Get and Create methods. This could become the last page for the gRPC tutorial. It could be called "Service Generation Options" or something like that. |
a8m
left a comment
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.
Looks good to me.
entproto/internal/entprototest/ent/schema/all_methods_service.go
Outdated
Show resolved
Hide resolved
entproto/internal/entprototest/ent/schema/one_method_service.go
Outdated
Show resolved
Hide resolved
entproto/internal/entprototest/ent/schema/two_method_service.go
Outdated
Show resolved
Hide resolved
Co-authored-by: Ariel Mashraki <[email protected]>
Co-authored-by: Ariel Mashraki <[email protected]>
Co-authored-by: Ariel Mashraki <[email protected]>
Co-authored-by: Ariel Mashraki <[email protected]>
rotemtam
left a comment
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.
LGTM
Great job @JeremyV2014, thanks for working on this!
Allow users to specify which methods they would like to generate for a gRPC service.