Open
Description
It seems that mergo.Map
doesn't process with interface{}
when merging slices.
Example:
package main
import (
"dario.cat/mergo"
"fmt"
)
type SliceStruct struct {
Values []string
}
func main() {
dst := SliceStruct{
Values: []string{"value1", "value2", "value3"},
}
src := map[string]interface{}{
"Values": []interface{}{"newValue1", "newValue2", "newValue3"},
}
err := mergo.Map(&dst, src, mergo.WithOverride)
if err != nil {
fmt.Println("mergo error:", err)
}
fmt.Printf("Updated struct: %+v\n", dst)
}
Error:
panic: reflect.Set: value of type []interface {} is not assignable to type []string
However, the type of Values
in map is actually []string
, which is the same as that in struct, not only the []interface{}
.
Additional:
mergo.WithAppendSlice
has the similar problem too:
mergo error: cannot append two slice with different type ([]interface {}, []string)
Metadata
Metadata
Assignees
Labels
No labels