The package documentation at http://golang.org/pkg/crypto/sha1/ does have an example that demonstrates this. It's stated as an example of the New function, but it's the only example on the page and it has a link right near the top of the page so it is worth looking at. The complete example is,
Code:
h := sha1.New()
io.WriteString(h, "His money is twice tainted: 'taint yours and 'taint mine.")
fmt.Printf("% x", h.Sum(nil))
You can actually do this in a much more concise and idiomatic manner:
// Assuming 'r' is set to some inbound net/http request
form_value := []byte(r.PostFormValue("login_password"))
sha1_hash := fmt.Sprintf("%x", sha1.Sum(form_value))
// Then output optionally, to test
fmt.Println(sha1_hash)
In this trivial example of a http.Request POST containing a login_password field, it is worth noting that fmt.Sprintf() called with %x converted the hash value to hex without having to include an import "encoding/hex" declaration.
( We used fmt.Sprintf() as opposed to fmt.Printf() as we were outputting a string to a variable assignment, not an io.Writer interface. )
Also of reference, is that the sha1.Sum() function verbosely instantiates in the same manner as the sha1.New() definition:
func New() hash.Hash {
d := new(digest)
d.Reset()
return d
}
func Sum(data []byte) [Size]byte {
var d digest
d.Reset()
d.Write(data)
return d.checkSum()
}
This holds true ( at least at the time of posting ) for the Sha library variants in Golang's standard crypto set, such as Sha512.
Lastly, if one wanted to, they could follow Golang's [to]String() implementation with something like func (h hash.Hash) String() string {...} to encapsulate the process.
That is most likely beyond the desired scope of the original question.