文件MD5

package main

import (
    "crypto/md5"
    "fmt"
    // "github.com/astaxie/beego"
    "io"
    "os"
)

func main() {
    var md5out string
    testFile := "server.go"
    fmt.Println(testFile)
    file, inerr := os.Open(testFile)
    if inerr == nil {
        md5h := md5.New()
        io.Copy(md5h, file)
        // fmt.Printf("%x", md5h.Sum([]byte("")))
        md5byte := md5h.Sum([]byte(""))
        md5out = fmt.Sprintf("%x", md5byte)
    } else {
        md5out = ""
    }
    fmt.Println(md5out)
}

原文地址:https://www.cnblogs.com/zhangym/p/6268334.html