Files
go-zero/core/hash/hash.go

27 lines
520 B
Go
Raw Permalink Normal View History

2020-07-26 17:09:05 +08:00
package hash
import (
"crypto/md5"
"encoding/hex"
2020-07-26 17:09:05 +08:00
"github.com/spaolacci/murmur3"
)
2021-02-19 18:14:34 +08:00
// Hash returns the hash value of data.
2020-07-26 17:09:05 +08:00
func Hash(data []byte) uint64 {
return murmur3.Sum64(data)
}
2021-02-19 18:14:34 +08:00
// Md5 returns the md5 bytes of data.
2020-07-26 17:09:05 +08:00
func Md5(data []byte) []byte {
digest := md5.New()
digest.Write(data)
return digest.Sum(nil)
}
2021-02-19 18:14:34 +08:00
// Md5Hex returns the md5 hex string of data.
// This function is optimized for better performance than fmt.Sprintf.
2020-07-26 17:09:05 +08:00
func Md5Hex(data []byte) string {
return hex.EncodeToString(Md5(data))
2020-07-26 17:09:05 +08:00
}