英文:
How to encode gob in UTF-8 in golang ?
问题
我正在使用gob.NewEncoder来编码字符串消息msg,但需要使用utf-8进行编码。
err = gob.NewEncoder(conn).Encode(msg)
我在Ruby接收器(Logstash)中收到一个警告,警告内容是Received an event that has a different character encoding than you configured ...:expected_charset=>"UTF-8"。
英文:
I am using gob.NewEncoder to encode string message msg but need to do it in utf-8.
err= gob.NewEncoder(conn).Encode(msg)
I am getting warning in Ruby receiver (Logstash) saying that Received an event that has a different character encoding than you configured ...:expected_charset=>"UTF-8"
答案1
得分: 1
当你调用Encode(msg)
时,你并没有发送UTF-8纯文本。
要发送纯文本:
conn.Write([]byte(msg)) // 假设msg是字符串
英文:
When you call Encode(msg)
, you are not sending UTF-8 plain text.
To send plain text:
conn.Write([]byte(msg)) // suppose msg is string
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论