sortJSON looks for any arrays in the unmarshalled JSON and sorts them in an arbitrary but deterministic order based on their content.
(i interface{})
| 123 | // sortJSON looks for any arrays in the unmarshalled JSON and sorts them in an |
| 124 | // arbitrary but deterministic order based on their content. |
| 125 | func sortJSON(i interface{}) uint64 { |
| 126 | if i == nil { |
| 127 | return 0 |
| 128 | } |
| 129 | switch i := i.(type) { |
| 130 | case map[string]interface{}: |
| 131 | return sortJSONMap(i) |
| 132 | case []interface{}: |
| 133 | return sortJSONArray(i) |
| 134 | default: |
| 135 | h := crc64.New(crc64.MakeTable(crc64.ISO)) |
| 136 | fmt.Fprint(h, i) |
| 137 | return h.Sum64() |
| 138 | } |
| 139 | } |
| 140 | |
| 141 | func sortJSONMap(m map[string]interface{}) uint64 { |
| 142 | var h uint64 |
no test coverage detected