41 lines
674 B
Go
41 lines
674 B
Go
package main
|
|
|
|
import (
|
|
"fmt"
|
|
"reflect"
|
|
|
|
"github.com/imdario/mergo"
|
|
)
|
|
|
|
type Foo struct {
|
|
Ignore []string
|
|
B int64
|
|
}
|
|
|
|
func main() {
|
|
src := Foo{
|
|
Ignore: []string{"one", "two", "three"},
|
|
B: 2,
|
|
}
|
|
dest := Foo{
|
|
Ignore: []string{"one", "two", "four", "seven"},
|
|
}
|
|
|
|
mergo.Merge(&dest, src, mergo.WithTransformers(StringSliceTransformer{}))
|
|
fmt.Println(dest)
|
|
// Will print
|
|
// {two 2}
|
|
}
|
|
|
|
type StringSliceTransformer struct {
|
|
}
|
|
|
|
// MergeStrings merges two strings
|
|
func (s StringSliceTransformer) Transformer(typ reflect.Type) func(dst, src reflect.Value) error {
|
|
if typ == reflect.TypeOf([]string{}) {
|
|
return func(dst, src reflect.Value) error {
|
|
|
|
}
|
|
}
|
|
}
|