package main import( . "fmt" "os" "io" "crypto/sha256" ) var usage = "usage: sha256sum [file]" func Error(s interface{}){ Fprintln(os.Stderr,s) os.Exit(1) } func main(){ var err error var bs []byte args := os.Args[1:] rd := os.Stdin switch(len(args)){ case 0: case 1: f := args[0] rd,err = os.Open(f) if err != nil { Error(err) } default: Error(usage) } bs,err = io.ReadAll(rd) if err != nil { Error(err) } rd.Close() sum := sha256.Sum256(bs) Printf("%x\n",sum) }