douche5961
douche5961
2017-01-21 22:49

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

已采纳

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条回答

  • dtw52353 dtw52353 4年前

    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
    
    点赞 评论 复制链接分享

为你推荐