本文整理汇总了Golang中github.com/mattermost/platform/model.Channel.ToJson方法的典型用法代码示例。如果您正苦于以下问题:Golang Channel.ToJson方法的具体用法?Golang Channel.ToJson怎么用?Golang Channel.ToJson使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/mattermost/platform/model.Channel
的用法示例。
在下文中一共展示了Channel.ToJson方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: join
func join(c *Context, w http.ResponseWriter, r *http.Request) {
params := mux.Vars(r)
channelId := params["channel_id"]
channelName := params["channel_name"]
var outChannel *model.Channel = nil
if channelId != "" {
if err, channel := JoinChannelById(c, c.Session.UserId, channelId); err != nil {
c.Err = err
c.Err.StatusCode = http.StatusForbidden
return
} else {
outChannel = channel
}
} else if channelName != "" {
if err, channel := JoinChannelByName(c, c.Session.UserId, c.TeamId, channelName); err != nil {
c.Err = err
c.Err.StatusCode = http.StatusForbidden
return
} else {
outChannel = channel
}
} else {
c.SetInvalidParam("join", "channel_id, channel_name")
return
}
w.Write([]byte(outChannel.ToJson()))
}
示例2: TestChannelStoreGet
func TestChannelStoreGet(t *testing.T) {
Setup()
o1 := model.Channel{}
o1.TeamId = model.NewId()
o1.DisplayName = "Name"
o1.Name = "a" + model.NewId() + "b"
o1.Type = model.CHANNEL_OPEN
Must(store.Channel().Save(&o1))
if r1 := <-store.Channel().Get(o1.Id); r1.Err != nil {
t.Fatal(r1.Err)
} else {
if r1.Data.(*model.Channel).ToJson() != o1.ToJson() {
t.Fatal("invalid returned channel")
}
}
if err := (<-store.Channel().Get("")).Err; err == nil {
t.Fatal("Missing id should have failed")
}
u1 := model.User{}
u1.TeamId = model.NewId()
u1.Email = model.NewId()
u1.Nickname = model.NewId()
Must(store.User().Save(&u1))
u2 := model.User{}
u2.TeamId = model.NewId()
u2.Email = model.NewId()
u2.Nickname = model.NewId()
Must(store.User().Save(&u2))
o2 := model.Channel{}
o2.TeamId = model.NewId()
o2.DisplayName = "Direct Name"
o2.Name = "a" + model.NewId() + "b"
o2.Type = model.CHANNEL_DIRECT
m1 := model.ChannelMember{}
m1.ChannelId = o2.Id
m1.UserId = u1.Id
m1.NotifyProps = model.GetDefaultChannelNotifyProps()
m2 := model.ChannelMember{}
m2.ChannelId = o2.Id
m2.UserId = u2.Id
m2.NotifyProps = model.GetDefaultChannelNotifyProps()
Must(store.Channel().SaveDirectChannel(&o2, &m1, &m2))
if r2 := <-store.Channel().Get(o2.Id); r2.Err != nil {
t.Fatal(r2.Err)
} else {
if r2.Data.(*model.Channel).ToJson() != o2.ToJson() {
t.Fatal("invalid returned channel")
}
}
}
示例3: join
func join(c *Context, w http.ResponseWriter, r *http.Request) {
params := mux.Vars(r)
channelId := params["channel_id"]
channelName := params["channel_name"]
var channel *model.Channel
var err *model.AppError
if channelId != "" {
channel, err = app.GetChannel(channelId)
} else if channelName != "" {
channel, err = app.GetChannelByName(channelName, c.TeamId)
} else {
c.SetInvalidParam("join", "channel_id, channel_name")
return
}
if err != nil {
c.Err = err
return
}
if channel.Type == model.CHANNEL_OPEN {
if !HasPermissionToTeamContext(c, channel.TeamId, model.PERMISSION_JOIN_PUBLIC_CHANNELS) {
return
}
}
if err = app.JoinChannel(channel, c.Session.UserId); err != nil {
c.Err = err
return
}
w.Write([]byte(channel.ToJson()))
}
示例4: TestChannelStoreGetByName
func TestChannelStoreGetByName(t *testing.T) {
Setup()
o1 := model.Channel{}
o1.TeamId = model.NewId()
o1.DisplayName = "Name"
o1.Name = "a" + model.NewId() + "b"
o1.Type = model.CHANNEL_OPEN
Must(store.Channel().Save(&o1))
if r1 := <-store.Channel().GetByName(o1.TeamId, o1.Name); r1.Err != nil {
t.Fatal(r1.Err)
} else {
if r1.Data.(*model.Channel).ToJson() != o1.ToJson() {
t.Fatal("invalid returned channel")
}
}
if err := (<-store.Channel().GetByName(o1.TeamId, "")).Err; err == nil {
t.Fatal("Missing id should have failed")
}
}