如何在 golang 中以 UTF-8 编码 gob?

How to encode gob in UTF-8 in golang ?

我正在使用 gob.NewEncoder 对字符串消息 msg 进行编码,但需要使用 utf-8 编码。

err= gob.NewEncoder(conn).Encode(msg)

我在 Ruby 接收器 (Logstash) 中收到警告说 收到的事件的字符编码与您配置的字符编码不同...:[=​​25=]=>"UTF-8"

当您调用 Encode(msg) 时,您发送的不是 UTF-8 纯文本。

要发送纯文本:

conn.Write([]byte(msg)) // suppose msg is string