gen icon indicating copy to clipboard operation
gen copied to clipboard

gen and protobuf

Open kanekv opened this issue 8 years ago • 5 comments

I want to use gen on structures defined by protobuf. But protobuf files are themselves generated and it is not recommended to edit them. Is there any way to get around this?

kanekv avatar May 09 '16 09:05 kanekv

Hmm, sounds like not a great idea. gen is for your types -- I assume that the generated proto files represent an external package's types?

clipperhouse avatar May 10 '16 00:05 clipperhouse

Why? Protobuf could be used to exchange data between my own services. They are my own types, just defined differently.

kanekv avatar May 10 '16 01:05 kanekv

Fair, though I don't have a good suggestion off the top of my head. Show me some sample code?

clipperhouse avatar May 10 '16 01:05 clipperhouse

Well there are not many things to show. Protobuf it self generates some interfaces for example.

type ChannelStoreClient interface { Ping(ctx context.Context, in _Client, opts ...grpc.CallOption) (_Response, error) .... }

One option would be to have a possibility to add those custom types to "gen" explicitly by command line argument for example.

gen -type 'ChannelStoreClient slice:"Where,Count,GroupBy[string]"'

or support comments like this // +gen slice:"Where,Count,GroupBy[string]" // +type ChannelStoreClient

pavelsmejkal avatar Jul 29 '16 08:07 pavelsmejkal

@Kane-Sendgrid @clipperhouse

This might help: https://github.com/Softwee/Anakin Anakin takes a GRPC and via AST allows me to get in the middle of it to control exactly what gets code generated. I plan to use it for a bigger code gen project.

clipperhouse/gen can then be used to produce types with extra functionality i need.

SO you are code generating code, and that produced code is used for another coe gen pass. I knwo the team at goa have written about this and have a multi.stage code generator too, which might be worth studying. i plan to look at it also.

joeblew99 avatar Jan 05 '17 14:01 joeblew99