go-examples/my-md5/main.go

24 lines
314 B
Go
Raw Normal View History

2017-07-08 08:35:19 +00:00
package main
import "fmt"
import "crypto/md5"
import "io"
import "log"
import "os"
func main() {
if len(os.Args) < 2 {
log.Fatalln("Usage my-md5 file")
}
f, err := os.Open(os.Args[1])
if err != nil {
log.Fatalln(err)
}
defer f.Close()
h := md5.New()
io.Copy(h, f)
fmt.Printf("%x\n", h.Sum(nil))
}