• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Golang utils.PageCheck函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: User_GetList

// 获取用户列表.
// @page: 从1开始的页数
// @return: users, total-count, err
func User_GetList(page, pagesize int, order string) ([]User, int64, error) {
	var db *goku.MysqlDB = GetDB()
	defer db.Close()

	page, pagesize = utils.PageCheck(page, pagesize)

	qi := goku.SqlQueryInfo{}
	qi.Limit = pagesize
	qi.Offset = pagesize * page
	if order == "" {
		qi.Order = "id desc"
	} else {
		qi.Order = order
	}

	var users []User
	err := db.GetStructs(&users, qi)
	if err != nil {
		goku.Logger().Errorln(err.Error())
		return nil, 0, err
	}

	total, err := db.Count("user", "")
	if err != nil {
		goku.Logger().Errorln(err.Error())
	}
	return users, total, nil
}
开发者ID:yonglehou,项目名称:ohlala,代码行数:31,代码来源:user.go


示例2: Comment_GetByPage

// @page: 从1开始
// @return: comments, total-count, err
func Comment_GetByPage(page, pagesize int, order string) ([]Comment, int64, error) {
	var db *goku.MysqlDB = GetDB()
	defer db.Close()

	page, pagesize = utils.PageCheck(page, pagesize)

	qi := goku.SqlQueryInfo{}
	qi.Limit = pagesize
	qi.Offset = page * pagesize
	if order == "" {
		qi.Order = "id desc"
	} else {
		qi.Order = order
	}
	var comments []Comment
	err := db.GetStructs(&comments, qi)
	if err != nil {
		goku.Logger().Errorln(err.Error())
		return nil, 0, err
	}

	total, err := db.Count("comment", "")
	if err != nil {
		goku.Logger().Errorln(err.Error())
	}

	return comments, total, nil
}
开发者ID:polaris1119,项目名称:ohlala,代码行数:30,代码来源:comment.go


示例3: User_GetFollowTopics

// 获取用户关注的话题列表
func User_GetFollowTopics(userId int64, page, pagesize int) ([]Topic, error) {
	var db *goku.MysqlDB = GetDB()
	defer db.Close()

	page, pagesize = utils.PageCheck(page, pagesize)

	qi := goku.SqlQueryInfo{}
	qi.Fields = "t.id, t.name, t.description, t.pic"
	qi.Join = " tf INNER JOIN `topic` t ON tf.topic_id=t.id"
	qi.Where = "tf.user_id=?"
	qi.Params = []interface{}{userId}
	qi.Limit = pagesize
	qi.Offset = pagesize * page
	qi.Order = "t.id desc"

	rows, err := db.Select("topic_follow", qi)

	if err != nil {
		goku.Logger().Errorln(err.Error())
		return nil, err
	}
	defer rows.Close()

	topics := make([]Topic, 0)
	for rows.Next() {
		topic := Topic{}
		err = rows.Scan(&topic.Id, &topic.Name, &topic.Description, &topic.Pic)
		if err != nil {
			goku.Logger().Errorln(err.Error())
			return nil, err
		}
		topics = append(topics, topic)
	}
	return topics, nil
}
开发者ID:t7er,项目名称:ohlala,代码行数:36,代码来源:user.go


示例4: Topic_GetFollowers

// 获取关注topicId的用户列表
func Topic_GetFollowers(topicId int64, page, pagesize int) ([]User, error) {
	var db *goku.MysqlDB = GetDB()
	defer db.Close()

	page, pagesize = utils.PageCheck(page, pagesize)

	qi := goku.SqlQueryInfo{}
	qi.Fields = "u.id, u.name, u.email, u.user_pic"
	qi.Join = " tf INNER JOIN `user` u ON tf.user_id=u.id"
	qi.Where = "tf.topic_id=?"
	qi.Params = []interface{}{topicId}
	qi.Limit = pagesize
	qi.Offset = pagesize * page
	qi.Order = "u.id desc"

	rows, err := db.Select("topic_follow", qi)

	if err != nil {
		goku.Logger().Errorln(err.Error())
		return nil, err
	}
	defer rows.Close()

	users := make([]User, 0)
	for rows.Next() {
		user := User{}
		err = rows.Scan(&user.Id, &user.Name, &user.Email, &user.UserPic)
		if err != nil {
			goku.Logger().Errorln(err.Error())
			return nil, err
		}
		users = append(users, user)
	}
	return users, nil
}
开发者ID:yonglehou,项目名称:ohlala,代码行数:36,代码来源:topic.go


示例5: FavoriteLink_ByUser

// 获取由用户收藏的link
// @page: 从1开始
func FavoriteLink_ByUser(userId int64, page, pagesize int) []Link {
	var db *goku.MysqlDB = GetDB()
	defer db.Close()

	page, pagesize = utils.PageCheck(page, pagesize)

	qi := goku.SqlQueryInfo{}
	qi.Fields = "l.id, l.user_id, l.title, l.context, l.topics, l.vote_up, l.vote_down, l.view_count, l.comment_count, l.create_time"
	qi.Join = " ufl INNER JOIN `link` l ON ufl.link_id=l.id"
	qi.Where = "ufl.user_id=?"
	qi.Params = []interface{}{userId}
	qi.Limit = pagesize
	qi.Offset = pagesize * page
	qi.Order = "ufl.create_time desc"

	rows, err := db.Select("user_favorite_link", qi)
	if err != nil {
		goku.Logger().Errorln(err.Error())
		return nil
	}
	links := make([]Link, 0)
	for rows.Next() {
		link := Link{}
		err = rows.Scan(&link.Id, &link.UserId, &link.Title, &link.Context, &link.Topics,
			&link.VoteUp, &link.VoteDown, &link.ViewCount, &link.CommentCount, &link.CreateTime)
		if err != nil {
			goku.Logger().Errorln(err.Error())
			return nil
		}
		links = append(links, link)
	}

	return links
}
开发者ID:huwenshu,项目名称:ohlala,代码行数:36,代码来源:favorite_link.go


示例6: CommentForUser_GetByPage

// 获取收到的评论列表
// @page: 从1开始
// @return: comments, total-count, err
func CommentForUser_GetByPage(userId int64, page, pagesize int, order string) ([]Comment, int64, error) {
	var db *goku.MysqlDB = GetDB()
	defer db.Close()

	page, pagesize = utils.PageCheck(page, pagesize)

	qi := goku.SqlQueryInfo{}
	qi.Limit = pagesize
	qi.Offset = page * pagesize
	qi.Where = "cfu.user_id=?"
	qi.Join = " cfu INNER JOIN `comment` c ON cfu.comment_id=c.id"
	qi.Fields = `c.id, c.user_id, c.link_id, c.parent_path, c.children_count, c.top_parent_id,
                c.parent_id, c.deep, c.status, c.content, c.create_time, c.vote_up, c.vote_down, c.reddit_score`

	if order == "" {
		qi.Order = "create_time desc"
	} else {
		qi.Order = order
	}

	qi.Params = []interface{}{userId}
	rows, err := db.Select("comment_for_user", qi)

	if err != nil {
		goku.Logger().Errorln(err.Error())
		return nil, 0, err
	}
	defer rows.Close()
	comments := make([]Comment, 0)
	for rows.Next() {
		c := Comment{}
		err = rows.Scan(&c.Id, &c.UserId, &c.LinkId, &c.ParentPath, &c.ChildrenCount,
			&c.TopParentId, &c.ParentId, &c.Deep, &c.Status, &c.Content,
			&c.CreateTime, &c.VoteUp, &c.VoteDown, &c.RedditScore)
		if err != nil {
			goku.Logger().Errorln(err.Error())
			return nil, 0, err
		}
		comments = append(comments, c)
	}

	total, err := db.Count("comment_for_user", "user_id=?", userId)
	if err != nil {
		goku.Logger().Errorln(err.Error())
	}

	return comments, total, nil
}
开发者ID:yonglehou,项目名称:ohlala,代码行数:51,代码来源:comment_for_user.go


示例7: Link_ForUser

// 获取属于某用户的link
// @page: 从1开始
// @orderType: 排序类型, hot:热门, hotc:热议, time:最新, vote:投票得分, ctvl:争议
func Link_ForUser(userId int64, orderType string, page, pagesize int) ([]Link, error) {
	var db *goku.MysqlDB = GetDB()
	defer db.Close()

	page, pagesize = utils.PageCheck(page, pagesize)

	qi := goku.SqlQueryInfo{}
	qi.Fields = "l.id, l.user_id, l.title, l.context, l.topics, l.vote_up, l.vote_down, l.view_count, l.click_count, l.comment_count, l.create_time"
	qi.Join = " ul INNER JOIN `link` l ON ul.link_id=l.id"
	qi.Where = "ul.user_id=?"
	qi.Params = []interface{}{userId}
	qi.Limit = pagesize
	qi.Offset = pagesize * page
	switch orderType {
	case golink.ORDER_TYPE_TIME: // 最新
		qi.Order = "l.id desc"
	case golink.ORDER_TYPE_HOTC: // 热议
		qi.Order = "l.comment_count desc, id desc"
	case golink.ORDER_TYPE_CTVL: // 争议
		qi.Order = "l.dispute_score desc, id desc"
	case golink.ORDER_TYPE_VOTE: // 得分
		qi.Order = "l.vote_up desc, id desc"
	default:
		qi.Order = "l.reddit_score desc, id desc"
	}

	rows, err := db.Select(LinkForUser_TableName(userId), qi)

	if err != nil {
		goku.Logger().Errorln(err.Error())
		return nil, err
	}
	defer rows.Close()

	links := make([]Link, 0)
	for rows.Next() {
		link := Link{}
		err = rows.Scan(&link.Id, &link.UserId, &link.Title, &link.Context, &link.Topics,
			&link.VoteUp, &link.VoteDown, &link.ViewCount, &link.ClickCount, &link.CommentCount, &link.CreateTime)
		if err != nil {
			goku.Logger().Errorln(err.Error())
			return nil, err
		}
		links = append(links, link)
	}
	return links, nil
}
开发者ID:yonglehou,项目名称:ohlala,代码行数:50,代码来源:link.go


示例8: Topic_GetTops

func Topic_GetTops(page, pagesize int) ([]Topic, error) {
	var db *goku.MysqlDB = GetDB()
	defer db.Close()

	page, pagesize = utils.PageCheck(page, pagesize)

	qi := goku.SqlQueryInfo{}
	qi.Limit = pagesize
	qi.Offset = page * pagesize
	qi.Order = "link_count desc"
	var topics []Topic
	err := db.GetStructs(&topics, qi)
	if err != nil {
		goku.Logger().Errorln(err.Error())
	}
	return topics, err
}
开发者ID:yonglehou,项目名称:ohlala,代码行数:17,代码来源:topic.go


示例9: Link_ByUser

// 获取由用户发布的link
// @page: 从1开始
func Link_ByUser(userId int64, page, pagesize int) []Link {
	var db *goku.MysqlDB = GetDB()
	defer db.Close()

	page, pagesize = utils.PageCheck(page, pagesize)

	qi := goku.SqlQueryInfo{}
	qi.Limit = pagesize
	qi.Offset = page * pagesize
	qi.Where = "`user_id`=? and `status`=0"
	qi.Params = []interface{}{userId}
	qi.Order = "id desc"
	var links []Link
	err := db.GetStructs(&links, qi)
	if err != nil {
		goku.Logger().Errorln(err.Error())
		return nil
	}
	return links
}
开发者ID:yonglehou,项目名称:ohlala,代码行数:22,代码来源:link.go


示例10: Link_ForTopic

// 获取属于某话题的link
// @page: 从1开始
func Link_ForTopic(topicId int64, page, pagesize int, sortType string, t string) ([]Link, error) {
	var db *goku.MysqlDB = GetDB()
	db.Debug = true
	defer db.Close()

	page, pagesize = utils.PageCheck(page, pagesize)

	sortField := "tl.reddit_score DESC,tl.link_id DESC"
	tableName := "tui_link_for_topic_top"
	switch {
	case sortType == golink.ORDER_TYPE_HOTC: //热议
		sortField = "l.comment_count DESC,tl.link_id DESC"
		tableName = "tui_link_for_topic_top"
	case sortType == golink.ORDER_TYPE_CTVL: //争议
		sortField = "tl.vote_abs_score ASC,tl.vote_add_score DESC,tl.link_id DESC"
		tableName = "tui_link_for_topic_hot"
	case sortType == golink.ORDER_TYPE_TIME: //最新
		sortField = "tl.link_id desc"
		tableName = "tui_link_for_topic_later"
	case sortType == golink.ORDER_TYPE_VOTE: //得分
		sortField = "tl.vote DESC, tl.link_id DESC"
		tableName = "tui_link_for_topic_vote"
	default: //热门
		sortField = "tl.reddit_score DESC,tl.link_id DESC"
		tableName = "tui_link_for_topic_top"
	}

	qi := goku.SqlQueryInfo{}
	qi.Fields = "l.id, l.user_id, l.title, l.context, l.topics, l.vote_up, l.vote_down, l.view_count, l.click_count, l.comment_count, l.create_time"
	qi.Join = " tl INNER JOIN `link` l ON tl.link_id=l.id"

	if sortType == golink.ORDER_TYPE_CTVL || sortType == golink.ORDER_TYPE_VOTE {
		qi.Where = "tl.topic_id=? AND tl.time_type=?"
		switch {
		case t == "all": //1:全部时间;2:这个小时;3:今天;4:这周;5:这个月;6:今年
			qi.Params = []interface{}{topicId, 1}
		case t == "hour":
			qi.Params = []interface{}{topicId, 2}
		case t == "day":
			qi.Params = []interface{}{topicId, 3}
		case t == "week":
			qi.Params = []interface{}{topicId, 4}
		case t == "month":
			qi.Params = []interface{}{topicId, 5}
		case t == "year":
			qi.Params = []interface{}{topicId, 6}
		default:
			qi.Params = []interface{}{topicId, 1}
		}
	} else {
		qi.Where = "tl.topic_id=?"
		qi.Params = []interface{}{topicId}
	}
	qi.Limit = pagesize
	qi.Offset = pagesize * page
	qi.Order = sortField

	rows, err := db.Select(tableName, qi)

	if err != nil {
		goku.Logger().Errorln(err.Error())
		return nil, err
	}
	defer rows.Close()

	links := make([]Link, 0)
	for rows.Next() {
		link := Link{}
		err = rows.Scan(&link.Id, &link.UserId, &link.Title, &link.Context, &link.Topics,
			&link.VoteUp, &link.VoteDown, &link.ViewCount, &link.ClickCount, &link.CommentCount, &link.CreateTime)
		if err != nil {
			goku.Logger().Errorln(err.Error())
			return nil, err
		}
		links = append(links, link)
	}
	return links, nil
}
开发者ID:yonglehou,项目名称:ohlala,代码行数:80,代码来源:link.go



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Golang admin.Context类代码示例发布时间:2022-05-28
下一篇:
Golang models.Link_ToVLink函数代码示例发布时间:2022-05-28
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap