jmattheis / goverter

Generate type-safe Go converters by simply defining an interface
https://goverter.jmattheis.de/
MIT License
502 stars 47 forks source link

Convert multiple source types to one target type #143

Open rwrz opened 5 months ago

rwrz commented 5 months ago

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 :+1: this issue if you like this functionality. If you have a specific use-case in mind, feel free to comment it.

jmattheis commented 5 months ago

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.