mirror of
https://github.com/avelino/awesome-go.git
synced 2024-11-14 16:42:23 +00:00
34 lines
441 B
Go
34 lines
441 B
Go
package main
|
|
|
|
import (
|
|
"crypto/md5"
|
|
"fmt"
|
|
"io"
|
|
"log"
|
|
"os"
|
|
)
|
|
|
|
func main() {
|
|
|
|
/*
|
|
Hashing and Checksums
|
|
*/
|
|
|
|
// Open file for reading
|
|
file, err := os.Open("test.txt")
|
|
if err != nil {
|
|
log.Fatal(err)
|
|
}
|
|
defer file.Close()
|
|
|
|
// Create new hasher, which is a writer interface
|
|
hasher := md5.New()
|
|
_, err = io.Copy(hasher, file)
|
|
if err != nil {
|
|
log.Fatal(err)
|
|
}
|
|
|
|
sum := hasher.Sum(nil)
|
|
fmt.Printf("Md5 checksum: %x\n", sum)
|
|
}
|