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 1 commit
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
8 changes: 7 additions & 1 deletion merge.go
Expand Up @@ -9,10 +9,13 @@
package mergo

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

var Skip = errors.New("mergo: skip custom transformer")
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

error var Skip should have name of the form ErrFoo

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

exported var Skip should have comment or be unexported


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 +85,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 != Skip {
return
}
}
}

Expand Down