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

support codegen off the structs after the protocol buffer gen has occured #56

Open
joeblew99 opened this issue Apr 20, 2017 · 3 comments
Labels

Comments

@joeblew99
Copy link

Currently the protobufs are used to code gen from, which is a awesome because that gets us our Types and the Transport and bindng sorted out.

But there are other things like DBs and Action Commands that can then also use code gen. We can codegen off the structs that the protobuf code gen made for us !

Its all based on this, which is nice and simple.
https://github.com/moul/protoc-gen-gotemplate

example:
Stellar uses it for a very large project.
There are 3 points where they gen from shown here:
https://github.com/stellar/horizon/search?utf8=%E2%9C%93&q=go+generate&type=

Here is one of the layers in the architecture where all Command Actions are generated from:
https://github.com/stellar/horizon/blob/master/src/github.com/stellar/horizon/main.go
From that generate command, it looks at all the action commands. Here is just one:
https://github.com/stellar/horizon/blob/master/src/github.com/stellar/horizon/actions_account.go

Wondering if this help. I think it has some merit

@moul moul added the question label Apr 20, 2017
@moul
Copy link
Owner

moul commented Apr 20, 2017

Hi @joeblew99 and thank you for your feedback,

Can you confirm that you are looking for a (or, the best) way to chain multiple generation tools, i.e.,

  1. protoc-gen-gotemplate generates code from protobuf files
  2. go-codegen uses the generated files from step 1. to generate new files ?

I'm pretty sure you already can chain protoc-gen-gotemplate with other code generation tools quite easily; would an example showing a chaining scenario be helpful?

@joeblew99
Copy link
Author

joeblew99 commented Apr 22, 2017

Hey @moul
thanks for being interested in this. I have some ideas and am really playing around with how to code gen the storage layer.
The Chat example uses NATS at the moment and to me its a great example of what can be code generated. Butting a store underneath it seems like the next local step.

yes please if you can make an example in the Chat demo with NATS.

  • using boltdb store as thats most portable or me and others to try.

I am emailing you a document outlining what i am building. Its quite a big 2 or 3 page document and easier to send to you with the images. I would like to get your feedback and also see if its something you would want added to this repo or i do it elsewhere. It extends from what you have.


I am going to try to extend the CHAT example to support catchup when the client is offline.
NATS can do that now i think, but not certain.
Its described here:
https://github.com/nats-io/go-nats-streaming#subscription-start-ie-replay-options

moul added a commit that referenced this issue Apr 24, 2017
@joeblew99
Copy link
Author

@moul thanks for adding this. Now i can get busy on codegen of the lower and upper layers.

Which leads me to this - Have you seen this ?
https://github.com/favadi/protoc-go-inject-tag

I am working on generating a strong typed DAL to BoltDB, and so i need to add a ton of meta data to the protobuf to hint what the data access layer codegen needs to do.

what do ya think ?
Is it redundant now that go generate works. Well i could put the meta data somewhere else other than the protobuf to drive it but i prefer the protobuf as its all in one place.
Its also possible with a KV store like BoltDB because you have a one to one mapping of the domain objects to the DB to a high degree.

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

No branches or pull requests

2 participants