Generate Getters Proposal Of Generation - #94
Open
pyrohedgehog wants to merge 1 commit into
Open
Conversation
… to accept arbitrary generated models more easily
Contributor
|
@pyrohedgehog that's entirely doable but here are a few questions and/or caveats.
The right place in the generator templates is templates/schema.gotmpl. We typically have there an optional method generation for MarshalBinary methods. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
After brief discussion in the discord. This is a quick draft around an idea of getters. Allowing interfaces to be used to accept arbitrary generated models more easily. The generated files have been edited by hand to quickly show a concept!
The main goal of this is, to be able to have more easily reusable components between models. In this case, say I wanted a single method that can take in an
ID, and aStatus, that would fit bothOrder, orPet.Now
with the current system, I would need to copy these fields into a hand written common type, having functionally identical code.
My Idea
By having getters, we could take the generated code, and create a simple interface like
and use the interface to handle our shared values.
Why not composite types?
scaryWhile we could have a common generated type
it seems more complicated to implement, changing core generation patterns, and currently, would not be able to call
aPet.ID. Some day being able to call struct literals such asaPet.IDis (hopefully) coming soon,, and that could make backwards compatibility easier, A) that seems far more complicated, and B) would rely on the newer go version to be implemented.