当前位置: 首页>>代码示例>>Golang>>正文


Golang gox.Context类代码示例

本文整理汇总了Golang中github.com/justintan/gox.Context的典型用法代码示例。如果您正苦于以下问题:Golang Context类的具体用法?Golang Context怎么用?Golang Context使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了Context类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: 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)
	}
}
开发者ID:justintan,项目名称:bbs,代码行数:29,代码来源:srv_topic_list.go

示例2: ServeGetChannels

func ServeGetChannels(c gox.Context) {
	channels, err := _db.GetChannels()
	if err != nil {
		c.SendCode(gox.ServerError)
	} else {
		c.SendData(gox.M{"channels": channels})
	}
}
开发者ID:justintan,项目名称:bbs,代码行数:8,代码来源:srv_channels.go

示例3: sendTopics

func sendTopics(c gox.Context, topics []*Topic) {
	prepareTopics(topics)
	c.SendData(gox.M{"topics": topics})
	go func() {
		for _, t := range topics {
			_cache.SetTopic(t)
		}
	}()
}
开发者ID:justintan,项目名称:bbs,代码行数:9,代码来源:srv_topic_list.go

示例4: ServeGetTopic

func ServeGetTopic(c gox.Context) {
	id := c.Request().Data.GetID("id")
	if id == 0 {
		c.SendCode(gox.BadRequest)
		return
	}

	topic, err := _db.GetTopic(id)
	switch {
	case err != nil:
		c.SendCode(gox.ServerError)
	case topic != nil:
		c.SendData(gox.M{"topic": topic})
	default:
		c.SendCode(gox.NotFound)
	}
}
开发者ID:justintan,项目名称:bbs,代码行数:17,代码来源:srv_topic.go

示例5: ServeRemoveComment

func ServeRemoveComment(c gox.Context) {
	id := c.Request().Data.GetID("comment_id")
	if id <= 0 {
		c.SendCode(gox.BadRequest)
		return
	}

	cmt, _ := GetComment(id)
	if cmt == nil {
		c.SendCode(gox.NotFound)
		return
	}

	err := _db.DelComment(id)
	if err != nil {
		c.SendCode(gox.ServerError)
	} else {
		c.SendCode(gox.OK)
	}
}
开发者ID:justintan,项目名称:bbs,代码行数:20,代码来源:srv_topic_comments.go

示例6: ServeRemoveTopic

func ServeRemoveTopic(c gox.Context) {
	id := c.Request().Data.GetID("topic_id")
	if id <= 0 {
		c.SendCode(gox.BadRequest)
		return
	}

	err := _db.DelTopic(id)
	if err != nil {
		c.SendCode(gox.ServerError)
	} else {
		_cache.DelTopic(id)
		c.SendCode(gox.OK)
	}
}
开发者ID:justintan,项目名称:bbs,代码行数:15,代码来源:srv_topic.go

示例7: ServeGetUserComments

func ServeGetUserComments(c gox.Context) {
	d := c.Request().Data
	userID := d.GetID("user_id")
	sinceID := d.GetID("since_id")
	size := d.DGetInt("size", DefaultPageSize)
	if sinceID <= 0 || size < 0 || userID <= 0 {
		c.SendCode(gox.BadRequest)
	}
	comments, err := _db.GetUserComments(userID, sinceID, size)
	if err != nil {
		c.SendCode(gox.ServerError)
	} else {
		prepareComments(comments)
		c.SendData(gox.M{"comments": comments})
	}
}
开发者ID:justintan,项目名称:bbs,代码行数:16,代码来源:srv_topic_comments.go

示例8: ServeGetCommentedTopics

func ServeGetCommentedTopics(c gox.Context) {
	d := c.Request().Data
	page := d.GetInt("page")
	size := d.DGetInt("size", DefaultPageSize)
	if page < 0 || size < 0 {
		c.SendCode(gox.BadRequest)
		return
	}

	topics, err := _db.GetCommentedTopics(c.UserID(), page, size)
	if err != nil {
		c.SendCode(gox.ServerError)
	} else {
		sendTopics(c, topics)
	}
}
开发者ID:justintan,项目名称:bbs,代码行数:16,代码来源:srv_topic_list.go

示例9: ServeGetTopicComments

func ServeGetTopicComments(c gox.Context) {
	d := c.Request().Data
	topicID := d.GetID("topic_id")
	sinceID := d.GetID("since_id")
	size := d.DGetInt("size", DefaultPageSize)
	desc := d.DGetBool("desc", true)
	if topicID <= 0 || sinceID < 0 || size < 0 {
		c.SendCode(gox.BadRequest)
	}

	comments, err := _db.GetComments(topicID, ItemTypeTopic, sinceID, size, desc)
	if err != nil {
		c.SendCode(gox.ServerError)
	} else {
		prepareComments(comments)
		c.SendData(gox.M{"comments": comments})
	}
}
开发者ID:justintan,项目名称:bbs,代码行数:18,代码来源:srv_topic_comments.go

示例10: ServeGetImages

func ServeGetImages(c gox.Context) {
	d := c.Request().Data
	id := d.GetID("album_id")
	t := d.GetInt("album_type")
	page := d.GetInt("page")
	size := d.DGetInt("size", 30)
	if id <= 0 || page < 0 || size < 0 {
		c.SendCode(gox.BadRequest)
		return
	}

	images, err := _db.GetImages(id, t, page, size)
	if err != nil {
		c.SendCode(gox.ServerError)
	} else {
		c.SendData(gox.M{"images": images})
	}
}
开发者ID:justintan,项目名称:bricks,代码行数:18,代码来源:srv.go

示例11: ServeGetChannelTopics

func ServeGetChannelTopics(c gox.Context) {
	d := c.Request().Data
	channelID := d.GetID("channel_id")
	page := d.GetInt("page")
	size := d.DGetInt("size", DefaultPageSize)
	if channelID <= 0 || page < 0 || size < 0 {
		c.SendCode(gox.BadRequest)
		return
	}

	order := TopicListOrder(d.DGetInt("order", int(OrderByCommentedAt)))

	topics, err := _db.GetChannelTopics(channelID, page, size, 0, order)
	if err != nil {
		c.SendCode(gox.ServerError)
	} else {
		sendTopics(c, topics)
	}
}
开发者ID:justintan,项目名称:bbs,代码行数:19,代码来源:srv_topic_list.go

示例12: changeTopicAction

func changeTopicAction(c gox.Context, action int, add bool) {
	id := c.Request().Data.GetID("topic_id")
	if id == 0 {
		c.SendCode(gox.BadRequest)
		return
	}

	t, _ := GetTopic(id)
	if t == nil {
		c.SendCode(gox.NotFound)
		return
	}

	var err error
	if add {
		err = _db.AddTopicAction(c.UserID(), id, action)
	} else {
		err = _db.DelTopicAction(c.UserID(), id, action)
	}

	if err != nil {
		c.SendCode(gox.ServerError)
		return
	}

	if add {
		switch action {
		case gox.ActionLike:
			t.LikesCount++
		case gox.ActionFavorite:
			t.FavoritesCount++
		default:
			break
		}
		if _callbacks.DidRecvTopicAction != nil {
			_callbacks.DidRecvTopicAction(c.UserID(), t, action)
		}
	} else {
		switch action {
		case gox.ActionLike:
			t.LikesCount--
			if t.LikesCount < 0 {
				t.LikesCount = 0
			}
		case gox.ActionFavorite:
			t.FavoritesCount--
			if t.FavoritesCount < 0 {
				t.FavoritesCount = 0
			}
		default:
			break
		}
	}
	_cache.SetTopic(t)
	c.SendData(gox.M{"topic": t})
}
开发者ID:justintan,项目名称:bbs,代码行数:56,代码来源:srv_topic_actions.go

示例13: 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})
}
开发者ID:justintan,项目名称:bbs,代码行数:48,代码来源:srv_topic_comments.go

示例14: ServeRemoveImage

func ServeRemoveImage(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.RemoveImage(id, t, img)
		if err != nil {
			c.SendCode(gox.ServerError)
		} else {
			c.SendCode(gox.OK)
		}
	}

}
开发者ID:justintan,项目名称:bricks,代码行数:23,代码来源:srv.go

示例15: 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})
	}
}
开发者ID:justintan,项目名称:bbs,代码行数:26,代码来源:srv_topic.go


注:本文中的github.com/justintan/gox.Context类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。