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

Skip to content

Conversation

@JeremyV2014
Copy link

Allow users to specify which methods they would like to generate for a gRPC service.

Jeremy Maxey-Vesperman added 3 commits November 11, 2021 00:49
Allow users to specify which methods they would like to generate for a gRPC service.
@rotemtam
Copy link
Contributor

Hey @JeremyV2014,
Thanks for working on this!

A few things:

Define the method enums with1 << iota like in https://github.com/ent/ent/blob/3ba2b4e1737a4db1cb7ee9b81c7bff5961f515fa/ent.go#L354-L360
For example, https://play.golang.org/p/HiXdR5Ck1Ni

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()


func Service() schema.Annotation {
return service{Generate: true}
func Service(methods ...Method) schema.Annotation {
Copy link
Contributor

@rotemtam rotemtam Nov 11, 2021

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

Copy link
Author

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.

Copy link
Contributor

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!

Copy link
Author

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!

@rotemtam
Copy link
Contributor

rotemtam commented Nov 12, 2021

The implementation looks right, thanks! Please add tests?

https://github.com/ent/contrib/tree/master/entproto#contributing

@JeremyV2014
Copy link
Author

Please add tests?

To internal/entprototest/service_test.go?

Copy link
Contributor

@rotemtam rotemtam left a 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).

Copy link
Contributor

@rotemtam rotemtam left a 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

@JeremyV2014
Copy link
Author

Also notice that CI is failing

Looks like I'm missing copyright headers in the new files.

@JeremyV2014 JeremyV2014 requested a review from rotemtam November 14, 2021 21:59
@JeremyV2014
Copy link
Author

Also if you can, please update the README file for entproto (in a separate PR is fine)

Should entproto.Service() get a higher header level? It seems like this is quite a bit of information to add to that section.

update the gRPC documentation on the ent site (also in a separate PR).

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.

Copy link
Member

@a8m a8m left a 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.

Jeremy Maxey-Vesperman and others added 3 commits November 15, 2021 09:30
Copy link
Contributor

@rotemtam rotemtam left a 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!

@rotemtam rotemtam merged commit 712b444 into ent:master Nov 15, 2021
@JeremyV2014 JeremyV2014 deleted the method-generation-control branch November 15, 2021 21:09
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