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

feat: chain with independent convert functions #5

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

kzantow
Copy link
Contributor

@kzantow kzantow commented Apr 1, 2024

Implementing 2-way conversion was not possible in most cases due to Golang package cycle restrictions. This PR (WiP) moves conversion to functions such that these are able to be defined outside of the packages where the target structs are defined. Take the following example:

models/v1/model.go
models/v2/model.go

.. v1/models cannot refer to v2/models AND have v2/models refer back to v1/models. This PR allows the custom conversion functions to be defined outside the origin structs, for example:

models/v1/model.go
models/v1to2/convert.go
models/v2/model.go

where the functions defined in v1to2/convert are able to reference BOTH v1/model and v2/model, e.g.:

func ConvertV1toV2(v1 v1.Model, v2 *v2.Model) error {
  ....
}

this allows the backwards migrations to also be defined, either in the same or another package, e.g.:

func ConvertV2toV1(v2 v2.Model, v1 *v1.Model) error {
  ....
}

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

Successfully merging this pull request may close these issues.

1 participant