github.com/argoproj/argo-events@v1.9.1/common/hash.go (about) 1 package common 2 3 import ( 4 "crypto/sha256" 5 "encoding/hex" 6 ) 7 8 func MustHash(v interface{}) string { 9 switch data := v.(type) { 10 case []byte: 11 hash := sha256.New() 12 if _, err := hash.Write(data); err != nil { 13 panic(err) 14 } 15 return hex.EncodeToString(hash.Sum(nil)) 16 case string: 17 return MustHash([]byte(data)) 18 default: 19 return MustHash([]byte(MustJSON(v))) 20 } 21 }