equal.go 924 B

123456789101112131415161718192021222324252627
  1. package awsutil
  2. import (
  3. "reflect"
  4. )
  5. // DeepEqual returns if the two values are deeply equal like reflect.DeepEqual.
  6. // In addition to this, this method will also dereference the input values if
  7. // possible so the DeepEqual performed will not fail if one parameter is a
  8. // pointer and the other is not.
  9. //
  10. // DeepEqual will not perform indirection of nested values of the input parameters.
  11. func DeepEqual(a, b interface{}) bool {
  12. ra := reflect.Indirect(reflect.ValueOf(a))
  13. rb := reflect.Indirect(reflect.ValueOf(b))
  14. if raValid, rbValid := ra.IsValid(), rb.IsValid(); !raValid && !rbValid {
  15. // If the elements are both nil, and of the same type the are equal
  16. // If they are of different types they are not equal
  17. return reflect.TypeOf(a) == reflect.TypeOf(b)
  18. } else if raValid != rbValid {
  19. // Both values must be valid to be equal
  20. return false
  21. }
  22. return reflect.DeepEqual(ra.Interface(), rb.Interface())
  23. }