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

Convert multiple source types to one target type #143

Open
rwrz opened this issue Apr 16, 2024 · 1 comment
Open

Convert multiple source types to one target type #143

rwrz opened this issue Apr 16, 2024 · 1 comment
Labels
feature New feature or request

Comments

@rwrz
Copy link

rwrz commented Apr 16, 2024

Is your feature request related to a problem? Please describe.
Sometimes, the target we want to generate require multiple sources.
Is it possible to be done using goverter somehow? Even if it is, would be great if we can pass multiple source parameters.

Describe the solution you'd like

type Source1 struct {
    Free bool
    Blocked bool
}

type Source2 struct {
   Id string
   Name string
}

type Target struct {
   Id string
   Name string
   Free bool
   Blocked bool
}

Describe alternatives you've considered
I've considered using 2 map functions, one then the other, but if the target is of the same type, it doesn't work.

Please 👍 this issue if you like this functionality. If you have a specific use-case in mind, feel free to comment it.

@jmattheis
Copy link
Owner

Similar #68

This is currently not possible, you could wrap both types into a separate object like this:

// goverter:converter
type Converter interface {
	// goverter:autoMap S1
	// goverter:autoMap S2
	Convert(source Sources) Target
}

type Sources struct {
	S1 Source1
	S2 Source2
}

But yeah, I want to support this use case.

@jmattheis jmattheis added the feature New feature or request label Apr 17, 2024
@jmattheis jmattheis changed the title Generate target from multiple sources Convert multiple source types to one target type Apr 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants