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

Feature request - option to create an interface as well as a struct, and getters and setters for properties #74

Open
teq0 opened this issue Apr 30, 2023 · 0 comments

Comments

@teq0
Copy link
Contributor

teq0 commented Apr 30, 2023

In many situations you want to be able to support multiple versions of schemas at the same time so that your customers don't all need to update their applications and services every time you bump a version. But if you are deserialising into strongly-typed, version-specific structs it's difficult to have efficient code that deals with all the common fields across versions because the different versions are different go types.

Since go "polymorphism" uses interfaces (i.e. methods and not properties) one way to deal with multiple versions would be to define interfaces that consist of getters/setters for all the fields, so that the different versioned structs can at least be accessed through lowest-common-denominator interface definitions e.g. everything implements the v1.0 interface, all versions including and above v1.1 support any new fields added in v1.1 etc.

You could probably do this using reflection at runtime, or maybe something with generics, but it seems like it would be less work all round to do it while generating the code, since you already have the field and struct definitions.

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

No branches or pull requests

1 participant