doutang6600 2017-04-07 14:01
浏览 23
已采纳

Golang RethinkDB ChangeFeed结构

I was wondering if someone could explain how to unmarshal my changefeed cursor value to a specific struct type.

var message map[string]interface{}

for chatFeedCursor.Next(&message) {
    fmt.Println(message)
}

map[new_val:map[club_id:ea2eb6e2-755f-4dad-922d-e3693b6e55c6 date:2017-04-07 14:48:17.714 +0100 +01:00 id:e389ab54-963e-4b33-9b34-adcb6ec5b17e message:what is the meaning of life? user_id:00ff679f-9421-4b8b-ae7f-d11cf2adaee2] old_val:]

However, I would like the response to be mapped to struct ChatMessage.

Update:

I've tried:

var message ChatMessage

However, it doesn't seem like any of my data gets set in the struct.

{ 0001-01-01 00:00:00 +0000 UTC}

My struct:

type ChatMessage struct {
    ID      string        `json:"id" gorethink:"id,omitempty"`
    UserID      string    `json:"user_id" gorethink:"user_id"`
    ClubID      string    `json:"club_id" gorethink:"club_id"`
    Message     string    `json:"message" gorethink:"message"`
    Date    time.Time     `json:"date" gorethink:"date"`
}

Thanks.

  • 写回答

1条回答 默认 最新

  • donglieshe4692 2017-04-07 14:18
    关注

    I figured it out!

    The problem was that I didn't specify a field on the rethinkdb change request.

    Previous code:

    chatFeedCursor, _ := gorethink.Table("club_chat").Changes().Run(gorethinkSession)
    

    Working Code:

    chatFeedCursor, _ := gorethink.Table("club_chat").Changes().Field("new_val").Run(gorethinkSession)
    

    Now the .Next() value maps to my struct with no issues.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 乌班图ip地址配置及远程SSH
  • ¥15 怎么让点阵屏显示静态爱心,用keiluVision5写出让点阵屏显示静态爱心的代码,越快越好
  • ¥15 PSPICE制作一个加法器
  • ¥15 javaweb项目无法正常跳转
  • ¥15 VMBox虚拟机无法访问
  • ¥15 skd显示找不到头文件
  • ¥15 机器视觉中图片中长度与真实长度的关系
  • ¥15 fastreport table 怎么只让每页的最下面和最顶部有横线
  • ¥15 java 的protected权限 ,问题在注释里
  • ¥15 这个是哪里有问题啊?