From db3f716104aef930d9a647fc9843d59143eacae2 Mon Sep 17 00:00:00 2001 From: Tom Bevan Date: Thu, 10 Feb 2022 12:43:30 +0000 Subject: [PATCH] fix example test and check if identifier call is for struct --- diff.go | 4 ++++ diff_examples_test.go | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) 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.