本文整理汇总了Golang中github.com/justintan/gox.Context.SendMsg方法的典型用法代码示例。如果您正苦于以下问题:Golang Context.SendMsg方法的具体用法?Golang Context.SendMsg怎么用?Golang Context.SendMsg使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/justintan/gox.Context
的用法示例。
在下文中一共展示了Context.SendMsg方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: ServeCreateTopic
func ServeCreateTopic(c gox.Context) {
t := &Topic{}
d := c.Request().Data
d.AssignTo(t, "param")
t.UserID = c.UserID()
if len(t.Content) == 0 {
c.SendMsg(gox.BadRequest, "missing content")
return
}
if t.ChannelID > 0 {
channel, _ := _db.GetChannel(t.ChannelID)
if channel == nil {
c.SendMsg(gox.NotFound, "channel not found")
return
}
}
err := _db.InsertTopic(t)
if err != nil {
c.SendCode(gox.ServerError)
} else {
_cache.SetTopic(t)
c.SendData(gox.M{"topic": t})
}
}
示例2: ServeGetLocalTopics
func ServeGetLocalTopics(c gox.Context) {
d := c.Request().Data
page := d.GetInt("page")
size := d.DGetInt("size", DefaultPageSize)
radius := d.DGetFloat64("radius", 60)
coord := c.Request().Header.GetCoordinate("coordinate")
if coord == nil {
coord = d.GetCoordinate("coordinate")
}
if coord == nil {
c.SendMsg(gox.BadRequest, "missing coordinate")
return
}
if page < 0 || size < 0 {
c.SendCode(gox.BadRequest)
return
}
order := TopicListOrder(d.DGetInt("order", int(OrderByCommentedAt)))
topics, err := _db.GetAreaTopics(coord.GetArea(radius), page, size, order)
if err != nil {
c.SendCode(gox.ServerError)
} else {
sendTopics(c, topics)
}
}
示例3: ServeGetUserTopics
func ServeGetUserTopics(c gox.Context) {
d := c.Request().Data
userID := d.DGetID("user_id", c.UserID())
sinceID := d.GetID("since_id")
size := d.DGetInt("size", DefaultPageSize)
switch {
case sinceID < 0:
c.SendMsg(gox.BadRequest, "invalid since_id")
case size < 0:
c.SendMsg(gox.BadRequest, "invalid size")
case userID <= 0:
c.SendMsg(gox.BadRequest, "missing user_id")
default:
topics, err := _db.GetUserTopics(userID, sinceID, size, 0)
if err != nil {
c.SendCode(gox.ServerError)
} else {
var u *accounts.User
for _, t := range topics {
prepareTopic(t)
if u == nil {
u = t.User
}
t.User = nil
}
c.SendData(gox.M{"topics": topics, "user": u})
}
}
}
示例4: ServeCreateTopicComment
func ServeCreateTopicComment(c gox.Context) {
d := c.Request().Data
cmt := &Comment{}
d.AssignTo(cmt, "param")
cmt.UserID = c.UserID()
cmt.ItemID = d.GetID("topic_id")
cmt.ItemType = ItemTypeTopic
if cmt.ItemID == 0 && cmt.ToCommentID == 0 {
c.SendMsg(gox.BadRequest, "missing item_id or to_comment_id")
return
}
if len(cmt.Content) == 0 {
c.SendMsg(gox.BadRequest, "missing content")
return
}
if cmt.ToCommentID > 0 {
cmt.ToComment, _ = GetComment(cmt.ToCommentID)
if cmt.ToComment == nil || cmt.ItemType != cmt.ToComment.ItemType {
c.SendCode(gox.NotFound)
return
}
cmt.ItemID = cmt.ToComment.ItemID
}
t, _ := GetTopic(cmt.ItemID)
if t == nil {
c.SendMsg(gox.NotFound, "topic not found")
return
}
err := _db.InsertComment(cmt)
if err != nil {
c.SendCode(gox.ServerError)
return
}
prepareComment(cmt, 1)
t.CommentsCount++
_cache.SetTopic(t)
_cache.SetComment(cmt)
if _callbacks.DidRecvComment != nil {
_callbacks.DidRecvComment(cmt)
}
c.SendData(gox.M{"comment": cmt})
}
示例5: ServeAddImage
func ServeAddImage(c gox.Context) {
d := c.Request().Data
id := d.GetID("album_id")
t := d.GetInt("album_type")
img := d.GetStr("image")
switch {
case id <= 0:
c.SendMsg(gox.BadRequest, "missing album_id")
case t <= 0:
c.SendMsg(gox.BadRequest, "missing album_type")
case len(img) == 0:
c.SendMsg(gox.BadRequest, "missing image")
default:
err := _db.InsertImage(id, t, img)
if err != nil {
c.SendCode(gox.ServerError)
} else {
c.SendCode(gox.OK)
}
}
}