Quantcast
Channel: Mattermost Discussion Forums - Latest posts
Viewing all articles
Browse latest Browse all 25788

GetChannels API fails in golang bot example

$
0
0

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>)
}

Viewing all articles
Browse latest Browse all 25788

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>