Skip to content

Instantly share code, notes, and snippets.

@metric-space
Created April 24, 2016 04:22
Show Gist options
  • Save metric-space/e62c527e1365c3b0086382132527e811 to your computer and use it in GitHub Desktop.
Save metric-space/e62c527e1365c3b0086382132527e811 to your computer and use it in GitHub Desktop.
go version of sha1sum
package main
import (
"crypto/sha1"
"fmt"
"io/ioutil"
"log"
"os"
)
func main() {
if len(os.Args) < 2 {
fmt.Println("Filename(s) missing")
os.Exit(1)
}
h := sha1.New()
for _, filename := range os.Args[1:] {
fdesc, error := ioutil.ReadFile(filename)
if error != nil {
defer log.Fatal(error)
continue
}
h.Write(fdesc)
h.Reset()
fmt.Printf("%s - %x\n", filename, h.Sum(nil))
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment