3 ms·
It sounds like you've decided to dislike go without ever having actually used it for anything in the "real world". There is a difference between a string and a
by mediocregopher 13y ago
It sounds like you've decided to dislike go without ever having actually used it for anything in the "real world".
There is a difference between a string and a byte array. A string is a string. A byte array is a []byte (byte slice). You have to explicitly cast from one to another. Neither are inherently utf8. A string is represented by a byte array under-the-hood, and string literals in your code are read as utf8 encoded. Strings themselves are not necessarily utf8 encoded, and if you need to use a different encoding there's libraries for that (unless you're using something really esoteric).
- lmm 13y agoSo what do you get when you read a file, or when a file is uploaded to your web server? What happens if you write a function that accepts a string as a parameter, but haven't noticed that you're implicitly assuming the string is utf8? (e.g. a function that formats one string using another - if the encodings are different you'll end up with a string that's invalid for either encoding, no?) The distinction between a string with one encoding and a string with another is subtle but vitally important - exactly the sort of thing a type system should take care of.
- kisielk 13y agoThere is a library in one of the Go subrepositories that handles transformation from other encodings to UTF-8: https://code.google.com/p/go/source/browse?repo=text#hg%2Fencoding https://code.google.com/p/go/source/browse?repo=text#hg%2Fen... If you're expecting to get data in other other encodings you could put together some detection and transformation at the point of ingress and convert to UTF-8 encoded text for the rest of your application.