diff --git a/.gitignore b/.gitignore index fc71c8e..c84d0fc 100644 --- a/.gitignore +++ b/.gitignore @@ -34,3 +34,4 @@ upper-words/upper-words longest-word/longest-word statecsv/statecsv go-financial/go-financial +my-fnv/my-fnv diff --git a/my-fnv/main.go b/my-fnv/main.go new file mode 100644 index 0000000..7cb978e --- /dev/null +++ b/my-fnv/main.go @@ -0,0 +1,23 @@ +package main + +import "fmt" +import "hash/fnv" +import "io" +import "log" +import "os" + +func main() { + if len(os.Args) < 2 { + log.Fatalln("Usage my-fmv file") + } + f, err := os.Open(os.Args[1]) + if err != nil { + log.Fatalln(err) + } + defer f.Close() + + h := fnv.New64() + + io.Copy(h, f) + fmt.Printf("%x\n", h.Sum64()) +}