Unicode Go和UTF-8编码-转换是否自动?

Unicode Go和UTF-8编码-转换是否自动?,unicode,encoding,go,utf-8,character-encoding,Unicode,Encoding,Go,Utf 8,Character Encoding,我正在使用Go发出http请求 request, err := http.NewRequest("GET", url, nil) 此请求如果成功,将返回响应 response, err := client.Do(request) 收到响应后,我想保存内容 content, err := ioutil.ReadAll(response.Body) ioutil.WriteFile(destination, content, 0644) 我看了一下回复的标题 response.Header.G

我正在使用Go发出http请求

request, err := http.NewRequest("GET", url, nil)
此请求如果成功,将返回响应

response, err := client.Do(request)
收到响应后,我想保存内容

content, err := ioutil.ReadAll(response.Body)
ioutil.WriteFile(destination, content, 0644)
我看了一下回复的标题

response.Header.Get("Content-Type")
我看到大多数都是UTF-8编码的,这很好。但也有一些有不同的编码。我知道Go内置了unicode支持。这是否意味着,如果我写一个big-5编码页面的内容,它将自动转换为utf-8?或者我是否需要使用big-5编码手动解码,并使用utf-8重新编码

基本上,我想确保所有被写入的内容都是utf-8编码的。实现这一目标的最佳方式是什么


谢谢

什么
ioutil.ReadAll
读取将使用
ioutil.WriteFile
写入,而不进行任何转换

如果你想强制UTF-8编码,你必须自己去编码,例如借助
golang.org/x/text/encoding{,/charmap}
和/或
unicode/UTF{8,16}


为各种各样的丑陋和痛苦做好准备。

相关/可能重复的“为各种各样的丑陋和痛苦做好准备”。是的。。。我希望用围棋来避免这种情况。我必须用Python处理这个问题。。。再也不会了。不管怎样,谢谢你的回答。由于mat在一些痛苦中感到满足,golang.org/x/net/html/charset可能会让他松一口气。