diff options
Diffstat (limited to 'tpl/collections/reflect_helpers.go')
-rw-r--r-- | tpl/collections/reflect_helpers.go | 12 |
1 files changed, 10 insertions, 2 deletions
diff --git a/tpl/collections/reflect_helpers.go b/tpl/collections/reflect_helpers.go index 69425fcb0..3d73b70e1 100644 --- a/tpl/collections/reflect_helpers.go +++ b/tpl/collections/reflect_helpers.go @@ -18,6 +18,7 @@ import ( "reflect" "time" + "github.com/mitchellh/hashstructure" "github.com/pkg/errors" ) @@ -42,18 +43,25 @@ func numberToFloat(v reflect.Value) (float64, error) { } } -// normalizes different numeric types to make them comparable. +// normalizes different numeric types if isNumber +// or get the hash values if not Comparable (such as map or struct) +// to make them comparable func normalize(v reflect.Value) interface{} { k := v.Kind() switch { + case !v.Type().Comparable(): + h, err := hashstructure.Hash(v.Interface(), nil) + if err != nil { + panic(err) + } + return h case isNumber(k): f, err := numberToFloat(v) if err == nil { return f } } - return v.Interface() } |