fix:调整

This commit is contained in:
Hiven
2023-08-08 10:53:28 +08:00
parent dcc3cc4a7d
commit ff86cceb17
4 changed files with 14 additions and 27 deletions

View File

@@ -5,10 +5,21 @@ import (
"crypto/sha256"
"encoding/json"
"fmt"
"reflect"
"sort"
)
func JsonHashKey(v interface{}) string {
if reflect.TypeOf(v).Kind() == reflect.String {
var obj interface{}
err := json.Unmarshal([]byte(v.(string)), &obj)
if err == nil {
// 反序列化成功,直接替换v
v = obj
}
}
h := sha256.New()
h.Write(marshalOrdered(v))
return fmt.Sprintf("%x", h.Sum(nil))