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

skip not match transformer #217

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 8 additions & 1 deletion merge.go
Expand Up @@ -9,10 +9,14 @@
package mergo

import (
"errors"
"fmt"
"reflect"
)

// ErrSkip Allow users to judge by the type of DST and SRC, and skip the check
var ErrSkip = errors.New("mergo: skip custom transformer")

func hasMergeableFields(dst reflect.Value) (exported bool) {
for i, n := 0, dst.NumField(); i < n; i++ {
field := dst.Type().Field(i)
Expand Down Expand Up @@ -82,7 +86,10 @@ func deepMerge(dst, src reflect.Value, visited map[uintptr]*visit, depth int, co
if config.Transformers != nil && !isReflectNil(dst) && dst.IsValid() {
if fn := config.Transformers.Transformer(dst.Type()); fn != nil {
err = fn(dst, src)
return
// Allow users to judge by the type of DST and SRC, and skip the check
if err != ErrSkip {
return
}
}
}

Expand Down