How to convert byte array to string in Go [duplicate]
The easiest method I use to convert byte
to string
is:
myString := string(myBytes[:])
The easiest way to convert []byte
to string
in Go:
myString := string(myBytes)
Note: to convert a "sha1 value to string" like you're asking, it needs to be encoded first, since a hash is binary. The traditional encoding for SHA hashes is hex (import "encoding/hex"
):
myString := hex.EncodeToString(sha1bytes)