Working with encodings
If there is a chance that your program will have to work with data produced by disparate systems, you should be aware of different text encodings. This is a huge topic, but this section should provide some pointers to scratch the surface.
How to do it...
- Use the
golang.org/x/text/encoding
package to deal with different encodings. - To find an encoding by name, use one of the following:
golang.org/x/text/encoding/ianaindex
golang.org/x/text/encoding/htmlindex
- Once you have an encoding, use it to translate text to and from UTF-8.
How it works...
Use one of the indexes to find an encoding. Then, use that encoding to read/write data:
package main import ( "fmt" "os" "golang.org/x/text/encoding/ianaindex" ) func main() { enc, err := ianaindex.MIME.Encoding("US-ASCII") ...