[Golang] 產生檔案的MD5 hash - Generate file MD5 hash in golang

此篇文章是一個用Golang產生檔案MD5的function範例

func genMd5(Abspath string) string {
	path, err := filepath.Abs(Abspath)
	if err != nil {
		panic("Convert file absolute path error: " + path)
	}

	f, err := os.Open(Abspath)
	if err != nil {
		log.Fatal(err)
	}
	defer f.Close()

	h := md5.New()
	if _, err := io.Copy(h, f); err != nil {
		log.Fatal(err)
	}

	return hex.EncodeToString(h.Sum(nil))
}