【问题标题】:How to encode gob in UTF-8 in golang ?如何在 golang 中以 UTF-8 编码 gob?
【发布时间】:2017-01-21 22:49:00
【问题描述】:

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

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

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

【问题讨论】:

    标签: go utf-8 encode


    【解决方案1】:

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

    发送纯文本:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-05-29
      • 2017-06-20
      • 2019-03-31
      • 2017-01-19
      • 2011-01-01
      • 2011-10-30
      • 2012-02-29
      相关资源
      最近更新 更多