gen and protobuf
kanekv opened this issue · 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?
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?
Why? Protobuf could be used to exchange data between my own services. They are my own types, just defined differently.
Fair, though I don't have a good suggestion off the top of my head. Show me some sample code?
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
@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.