The Go Programming Language Specification
String types
A string type represents the set of string values. A string value is a
(possibly empty) sequence of bytes.
Conversions
Conversions to and from a string type
Converting a slice of bytes to a string type yields a string whose
successive bytes are the elements of the slice.
string([]byte{'h', 'e', 'l', 'l', '\xc3', '\xb8'}) // "hellø"
string([]byte{}) // ""
string([]byte(nil)) // ""
type MyBytes []byte
string(MyBytes{'h', 'e', 'l', 'l', '\xc3', '\xb8'}) // "hellø"
Converting a value of a string type to a slice of bytes type yields a
slice whose successive elements are the bytes of the string.
[]byte("hellø") // []byte{'h', 'e', 'l', 'l', '\xc3', '\xb8'}
[]byte("") // []byte{}
MyBytes("hellø") // []byte{'h', 'e', 'l', 'l', '\xc3', '\xb8'}
A string value is a (possibly empty) sequence of bytes. A string value may or may not represent Unicode characters encoded in UTF-8. There is no interpretation of the bytes during the conversion from byte
slice to string
nor from string
to byte
slice. Therefore, the bytes will not be changed and the conversions will not fail.