doujuegai8830 2016-11-03 17:04
浏览 20

无法获得golang中最重要的频道的列表

I am trying to create a bot and retrieve the list of channels. I used the bot example in repository and it is mostly working, except for the part where it has to get the list of channels.

Either I am doing something silly or GetChannels API really does not work the way it is described in bot_sample.go . I made a smaller separate function to test that part.

Adding code here for better readability:

func mattermostPrintChannels(client *mattermost.Client) {
    channelsResult, err := client.GetChannels("")
    if err != nil {
        fmt.Print("Couldn't get channels: ", err)
        return
    }
    channelList := channelsResult.Data.(*mattermost.ChannelList)
    fmt.Print("Channels:")
    for _, channel := range channelList.Channels {
        fmt.Printf("%s -> %s", channel.Id, channel.DisplayName)
    }
}

This code gives me the error:

./mattermost.go:30: channelList.Channels undefined (type *model.ChannelList has no field or method Channels)

Now if I just print the contents of ChannelList variable (using spew), I get the following:

channelList:  :  ([]interface {}) (len=1 cap=1) {
 (*model.ChannelList)(<nil>)
}
  • 写回答

1条回答 默认 最新

  • dtt5830659 2016-11-07 15:07
    关注

    JimB is correct. The model.ChannelList type used to be a struct, but it recently changed to []*model.Channel. You'll want to change

    for _, channel := range channelList.Channels {
    

    to

    for _, channel := range *channelList {
    
    评论

报告相同问题?

悬赏问题

  • ¥15 多址通信方式的抗噪声性能和系统容量对比
  • ¥15 winform的chart曲线生成时有凸起
  • ¥15 msix packaging tool打包问题
  • ¥15 finalshell节点的搭建代码和那个端口代码教程
  • ¥15 用hfss做微带贴片阵列天线的时候分析设置有问题
  • ¥15 Centos / PETSc / PETGEM
  • ¥15 centos7.9 IPv6端口telnet和端口监控问题
  • ¥20 完全没有学习过GAN,看了CSDN的一篇文章,里面有代码但是完全不知道如何操作
  • ¥15 使用ue5插件narrative时如何切换关卡也保存叙事任务记录
  • ¥20 海浪数据 南海地区海况数据,波浪数据