golang获取文件的md5
直接展示代码
func md5sum(filepath string) (string, error) { f, err := os.Open(filepath) if err != nil { str1 := "Open err" return str1, err } defer f.Close() body, err := ioutil.ReadAll(f) if err != nil { str2 := "ioutil.ReadAll" return str2, err } md5 := fmt.Sprintf("%x", md5.Sum(body)) runtime.GC() return md5, nil }