August 21, 2015
Go, Strings, and Character Encoding
I recently had a conversation with a friend about how UTF-8 and character encoding works in general, centered around why strings seem weird in Go if you’re used to how they’re handled in other languages.
The way that Go handles strings is pretty cool: a string is slice of bytes. Period. End of story.
It also just so happens that a Go program is defined as a sequence of UTF-8 characters (that’s all that is supported), so unless you insert raw bytes into them using escapes, a string literal is always UTF-8 in Go.
Read more