DeepHashObject writes specified object to hash using the spew library which follows pointers and prints actual values of the nested objects ensuring the hash does not change when a pointer changes.
(hasher hash.Hash, objectToWrite interface{})
| 32 | // which follows pointers and prints actual values of the nested objects |
| 33 | // ensuring the hash does not change when a pointer changes. |
| 34 | func DeepHashObject(hasher hash.Hash, objectToWrite interface{}) error { |
| 35 | hasher.Reset() |
| 36 | printer := spew.ConfigState{ |
| 37 | Indent: " ", |
| 38 | SortKeys: true, |
| 39 | DisableMethods: true, |
| 40 | SpewKeys: true, |
| 41 | } |
| 42 | |
| 43 | _, err := printer.Fprintf(hasher, "%#v", objectToWrite) |
| 44 | return err |
| 45 | } |
| 46 | |
| 47 | // ComputeHash returns a hash value calculated from the provided object. |
| 48 | // The hash will be safe encoded to avoid bad words. |