diff --git a/diff.go b/diff.go index f7e1b84..8ac8bd0 100644 --- a/diff.go +++ b/diff.go @@ -227,6 +227,10 @@ func tagName(tag string, f reflect.StructField) string { } func identifier(tag string, v reflect.Value) interface{} { + if v.Kind() != reflect.Struct { + return nil + } + for i := 0; i < v.NumField(); i++ { if hasTagOption(tag, v.Type().Field(i), "identifier") { return v.Field(i).Interface() diff --git a/diff_examples_test.go b/diff_examples_test.go index 2885eb7..e43c29d 100644 --- a/diff_examples_test.go +++ b/diff_examples_test.go @@ -312,7 +312,7 @@ func ExampleComplexSlicePatch() { fmt.Printf("Patched %d entries and encountered %d errors", len(patchLog), patchLog.ErrorCount()) - //Output: Patched 7 entries and encountered 4 errors + //Output: Patched 7 entries and encountered 3 errors } //ExampleComplexMapPatch demonstrates how to use the Patch function for complex slices.