Skip to content

feat: chain with independent convert functions#5

Merged
kzantow merged 9 commits into
mainfrom
add-convert-functions
Dec 22, 2025
Merged

feat: chain with independent convert functions#5
kzantow merged 9 commits into
mainfrom
add-convert-functions

Conversation

@kzantow

@kzantow kzantow commented Apr 1, 2024

Copy link
Copy Markdown
Contributor

Implementing 2-way conversion was not possible in most cases due to Golang package cycle restrictions. This PR 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 {
  ....
}

Signed-off-by: Keith Zantow <kzantow@gmail.com>
kzantow added 4 commits March 12, 2025 02:34
Signed-off-by: Keith Zantow <kzantow@gmail.com>
Signed-off-by: Keith Zantow <kzantow@gmail.com>
Signed-off-by: Keith Zantow <kzantow@gmail.com>
@kzantow kzantow force-pushed the add-convert-functions branch from 14968a9 to 8d748a7 Compare October 10, 2025 14:38
Signed-off-by: Keith Zantow <kzantow@gmail.com>
Signed-off-by: Keith Zantow <kzantow@gmail.com>
Signed-off-by: Keith Zantow <kzantow@gmail.com>
@wagoodman wagoodman self-requested a review October 14, 2025 15:39
@kzantow kzantow merged commit 55f3734 into main Dec 22, 2025
7 checks passed
@kzantow kzantow deleted the add-convert-functions branch December 22, 2025 22:01
@kzantow kzantow added the enhancement New feature or request label Dec 22, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants