package util import ( "crypto/sha256" "fmt" "io" "os" ) // 计算文件的hash func CalacHash(rfile string) string { // 获取到真实地址 // file, err := os.Open(rfile) if err != nil { panic(err) } defer file.Close() // initlize hash object hash := sha256.New() // write file into hash object if _, err := io.Copy(hash, file); err != nil { panic(err) } // get hash value hashBytes := hash.Sum(nil) //converto to hash string hastString := fmt.Sprintf("%x", hashBytes) return hastString }