Created
April 24, 2016 04:22
-
-
Save metric-space/e62c527e1365c3b0086382132527e811 to your computer and use it in GitHub Desktop.
go version of sha1sum
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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