Skip to content

Instantly share code, notes, and snippets.

@kadel
Created June 6, 2019 13:53
Show Gist options
  • Select an option

  • Save kadel/738df00257d41c570ce3168c0c92ee76 to your computer and use it in GitHub Desktop.

Select an option

Save kadel/738df00257d41c570ce3168c0c92ee76 to your computer and use it in GitHub Desktop.
package main
import (
"crypto/sha1"
"fmt"
"io"
"io/ioutil"
"log"
"os"
"path/filepath"
"strings"
)
func main() {
var sums []byte
filepath.Walk(".", func(path string, info os.FileInfo, err error) error {
if strings.Contains(path, ".git") {
return nil
}
if info.IsDir() {
return nil
}
if !info.Mode().IsRegular() {
return nil
}
filename := fmt.Sprintf(path)
f, err := os.Open(filename)
if err != nil {
log.Fatal(err)
}
defer f.Close()
h := sha1.New()
if _, err := io.Copy(h, f); err != nil {
log.Fatal(err)
}
sum := h.Sum(nil)
sums = append(sums, []byte(fmt.Sprintf("%s | %x\n", filename, sum))...)
return nil
})
ioutil.WriteFile("sha1sums.txt", sums, 0644)
return
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment