我想从一个结构体数组生成一个唯一的哈希值。顺序可能不同,但值是相同的。
例子:
编辑:基本上想法是生成一个用于缓存的唯一哈希!我想要将每个结构体的独立哈希组合起来!
例子:
type MyStruct struct {
ID string
Parameters map[string]interface{}
}
arr:= []MyStruct{MyStruct{ID: "test", Parameters: map[string]interface{}{"key": true, "key2": "value"} }, MyStruct{ID: "test2", Parameters: map[string]interface{}{"key2": "value", "key": true} }}
//The order is different even inside the Parameters fields
arr:= []MyStruct{MyStruct{ID: "test2", Parameters: map[string]interface{}{"key2": "value", "key": true} },MyStruct{ID: "test", Parameters: map[string]interface{}{"key": true, "key2": "value"} }}
在两种情况下,哈希值应该是相同的,因为结构体内部的值是相同的。编辑:基本上想法是生成一个用于缓存的唯一哈希!我想要将每个结构体的独立哈希组合起来!