[X] Yes, but it does not include related information regarding my question.
[ ] Yes, but the steps described do not work.
[ ] Yes, but I am having difficulty understanding it and want clarification.
Describe your question
I'm wondering why there isn't the possibility to ask for the Converter interface when using mapExtend ?
Taking the documentation exemple, this would give something like this :
// goverter:converter
type Converter interface {
// goverter:mapExtend FullName ExtendFullName
// goverter:mapExtend Age DefaultAge
Convert(source Input) Output
}
type Input struct {
ID int
FirstName string
LastName string
}
type Output struct {
ID int
FullName string
Age int
}
func ExtendFullName(c Converter, source Input) string {
return source.FirstName + " " + source.LastName
}
func DefaultAge() int { return 42 }
This would perfectly solve my use case, but maybe there's another solution :
// goverter:converter
type Converter interface {
// goverter:mapExtend Car ExtendCar
Convert(source Input) Output
ConvertBmwToCar(source *Bmw) *outputBmw
ConvertFerrariToCar(source *Ferrari) *outputFerrari
}
func ExtendCar(input *Input) []Car {
// I need Converter here so that I can loop on Bmw and Ferrari's array of the Input struct and
// call c.ConvertBmwToCar(input.Bmw[0]) || c.ConvertFerrariToCar(input.Ferrari[0])
}
type Input struct {
Bmw []*Bmw
Ferrari []*Ferrari
}
type Car interface{}
// implement Car
type outputBmw struct{}
// implement Car
type outputFerrari struct{}
type Output {
Car []Car
}
Have you read the project readme?
Describe your question I'm wondering why there isn't the possibility to ask for the Converter interface when using mapExtend ?
Taking the documentation exemple, this would give something like this :
This would perfectly solve my use case, but maybe there's another solution :