Skip to content

Commit

Permalink
Issue #2 fixed: errors now have idiomatic naming.
Browse files Browse the repository at this point in the history
  • Loading branch information
darccio committed Jun 25, 2014
1 parent 873aa35 commit 6af8196
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
12 changes: 6 additions & 6 deletions mergo.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ import (

// Errors reported by Mergo when it finds invalid arguments.
var (
NilArgumentsErr = errors.New("src and dst must not be nil")
DifferentArgumentsTypesErr = errors.New("src and dst must be of same type")
NotSupportedErr = errors.New("only structs and maps are supported")
ErrNilArguments = errors.New("src and dst must not be nil")
ErrDifferentArgumentsTypes = errors.New("src and dst must be of same type")
ErrNotSupported = errors.New("only structs and maps are supported")
)

// During deepMerge, must keep track of checks that are
Expand Down Expand Up @@ -115,15 +115,15 @@ func deepMerge(dst, src reflect.Value, visited map[uintptr]*visit, depth int) er
// any exported field.
func Merge(dst interface{}, src interface{}) error {
if dst == nil || src == nil {
return NilArgumentsErr
return ErrNilArguments
}
vDst := reflect.ValueOf(dst).Elem()
vSrc := reflect.ValueOf(src)
if vDst.Type() != vSrc.Type() {
return DifferentArgumentsTypesErr
return ErrDifferentArgumentsTypes
}
if vDst.Kind() != reflect.Struct && vDst.Kind() != reflect.Map {
return NotSupportedErr
return ErrNotSupported
}
return deepMerge(vDst, vSrc, make(map[uintptr]*visit), 0)
}
4 changes: 2 additions & 2 deletions mergo_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,15 @@ type complexTest struct {
}

func TestNil(t *testing.T) {
if err := Merge(nil, nil); err != NilArgumentsErr {
if err := Merge(nil, nil); err != ErrNilArguments {
t.Fail()
}
}

func TestDifferentTypes(t *testing.T) {
a := simpleTest{42}
b := 42
if err := Merge(&a, b); err != DifferentArgumentsTypesErr {
if err := Merge(&a, b); err != ErrDifferentArgumentsTypes {
t.Fail()
}
}
Expand Down

0 comments on commit 6af8196

Please sign in to comment.