// Paging 产生分页信息
490156
func Paging(curPage int, pageSize int, totalRecords int, items interface{}) Page {

	totalPages := int(totalRecords) / pageSize
	if totalPages == 0 {
		totalPages = 1
	}

	if int(totalRecords)%pageSize != 0 {
		totalPages++
	}

	return Page{
		Page:         curPage,
		Size:         pageSize,
		TotalRecords: int(totalRecords),
		TotalPages:   totalPages,
		Items:        items,
	}
}
597200
func GetPageCount(i int) uint64 {
	switch {
	case i > 0:
		// 返回成功数
		return pageSum[0]
	case i < 0:
		// 返回失败数
		return pageSum[1]
	case i == 0:
	}
	// 返回总数
	return pageSum[0] + pageSum[1]
}
1308803
func (c *Client) Page(msg *Page) error {
	if msg.UserId == "" && msg.AnonymousId == "" {
		return errors.New("You must pass either an 'anonymousId' or 'userId'.")
	}

	msg.Type = "page"
	c.queue(msg)

	return nil
}
723668
func (api *PublicWhisperAPI) Info(ctx context.Context) Info {
	stats := api.w.Stats()
	return Info{
		Memory:         stats.memoryUsed,
		Messages:       len(api.w.messageQueue) + len(api.w.p2pMsgQueue),
		MinPow:         api.w.MinPow(),
		MaxMessageSize: api.w.MaxMessageSize(),
	}
}
344898
func (p PageGroup) Slice(in interface{}) (interface{}, error) {
	switch items := in.(type) {
	case PageGroup:
		return items, nil
	case []interface{}:
		groups := make(PagesGroup, len(items))
		for i, v := range items {
			g, ok := v.(PageGroup)
			if !ok {
				return nil, fmt.Errorf("type %T is not a PageGroup", v)
			}
			groups[i] = g
		}
		return groups, nil
	default:
		return nil, fmt.Errorf("invalid slice type %T", items)
	}
}
814003
func (u *User) GetFollowing(page int) ([]*User, error) {
	users := make([]*User, 0, ItemsPerPage)
	sess := x.Limit(ItemsPerPage, (page-1)*ItemsPerPage).Where("follow.user_id=?", u.ID)
	if setting.UsePostgreSQL {
		sess = sess.Join("LEFT", "follow", `"user".id=follow.follow_id`)
	} else {
		sess = sess.Join("LEFT", "follow", "user.id=follow.follow_id")
	}
	return users, sess.Find(&users)
}
1047473
func (cg *CgroupV1) GetHugepageLimitData(pid int, cgPath string) ([]rspec.LinuxHugepageLimit, error) {
	if filepath.IsAbs(cgPath) {
		path := filepath.Join(cg.MountPath, "hugetlb", cgPath)
		if _, err := os.Stat(path); err != nil {
			if os.IsNotExist(err) {
				return nil, specerror.NewError(specerror.CgroupsAbsPathRelToMount, fmt.Errorf("In the case of an absolute path, the runtime MUST take the path to be relative to the cgroups mount point"), rspec.Version)
			}
			return nil, err
		}
	}
	lh := []rspec.LinuxHugepageLimit{}
	pageSizes, err := getHugePageSize()
	if err != nil {
		return lh, err
	}
	for _, pageSize := range pageSizes {
		maxUsage := strings.Join([]string{"hugetlb", pageSize, "limit_in_bytes"}, ".")
		filePath := filepath.Join(cg.MountPath, "hugetlb", cgPath, maxUsage)
		if !filepath.IsAbs(cgPath) {
			subPath, err := GetSubsystemPath(pid, "hugetlb")
			if err != nil {
				return lh, err
			}
			if !strings.Contains(subPath, cgPath) {
				return nil, fmt.Errorf("cgroup subsystem %s is not mounted as expected", "hugetlb")
			}
			filePath = filepath.Join(cg.MountPath, "hugetlb", subPath, maxUsage)
		}
		contents, err := ioutil.ReadFile(filePath)
		if err != nil {
			if os.IsNotExist(err) {
				return nil, specerror.NewError(specerror.CgroupsPathAttach, fmt.Errorf("The runtime MUST consistently attach to the same place in the cgroups hierarchy given the same value of `cgroupsPath`"), rspec.Version)
			}

			return lh, err
		}
		res, err := strconv.ParseUint(strings.TrimSpace(string(contents)), 10, 64)
		if err != nil {
			return nil, err
		}
		pageLimit := rspec.LinuxHugepageLimit{}
		pageLimit.Pagesize = pageSize
		pageLimit.Limit = res
		lh = append(lh, pageLimit)
	}

	return lh, nil
}
1123611
func (r *rest) AppInfo(c *gin.Context) {
	resp := r.server.NewResponse()
	defer resp.Close()

	if ir := r.server.HandleInfoRequest(resp, c.Request); ir != nil {
		r.server.FinishInfoRequest(resp, c.Request, ir)
	}
	osin.OutputJSON(resp, c.Writer, c.Request)
}
105645
func Pagination(pagination interface{}, opts Options) (*Tag, error) {
	if p, ok := pagination.(Paginator); ok {
		return p.Tag(opts)
	}

	p := Paginator{
		Page:    1,
		PerPage: 20,
	}

	return p.TagFromPagination(pagination, opts)
}
457726
func (c *Connection) Paginate(page int, perPage int) *Query {
	return Q(c).Paginate(page, perPage)
}
511703
func (m *MWApi) Read(pageName string) (*Page, error) {
	query := map[string]string{
		"action":  "query",
		"prop":    "revisions",
		"titles":  pageName,
		"rvlimit": "1",
		"rvprop":  "content|timestamp|user|comment",
	}
	body, err := m.API(query)
	if err != nil {
		return nil, err
	}

	var response Response
	err = json.Unmarshal(body, &response)
	if err != nil {
		return nil, err
	}

	if len(response.Query.Pages) != 1 {
		return nil, errors.New("received unexpected number of pages")
	}

	// we use a hacky way of extracting the map's lone value
	var page *Page
	for _, pg := range response.Query.Pages {
		page = &pg
	}
	return page, nil
}
663754
func PageAndCount(db *mgo.Database, collection string, query bson.M, offset int, limit int, result interface{}) (total int, err error) {
	err = WithC(db, collection, func(c *mgo.Collection) error {
		total, err = c.Find(query).Count()
		if err != nil {
			return err
		}
		return c.Find(query).Skip(offset).Limit(limit).All(result)
	})
	return total, err
}
1110065
func (pr *PagingResult) Decode(v interface{}) (err error) {
	res := Result{
		"data": pr.Data(),
	}
	return res.Decode(v)
}
895201
func (l *Client) GetTopicSummary(topic string, limit int) (TopicSummary, error) {
	res := ApiResp{}
	data := TopicSummary{}
	params := url.Values{}

	if limit > 0 {
		params.Add("limit", strconv.Itoa(limit))
	}

	err := l.Get(parseLyticsURL(topicEndpoint, map[string]string{"topicId": topic}), params, nil, &res, &data)
	if err != nil {
		return data, err
	}

	return data, nil
}
1238247
func paginate(page int, choices []string, sel int) ([]string, int) {
	// the number of elements to show in a single page
	var pageSize int
	// if the select has a specific page size
	if page != 0 {
		// use the specified one
		pageSize = page
		// otherwise the select does not have a page size
	} else {
		// use the package default
		pageSize = PageSize
	}

	var start, end, cursor int

	if len(choices) < pageSize {
		// if we dont have enough options to fill a page
		start = 0
		end = len(choices)
		cursor = sel

	} else if sel < pageSize/2 {
		// if we are in the first half page
		start = 0
		end = pageSize
		cursor = sel

	} else if len(choices)-sel-1 < pageSize/2 {
		// if we are in the last half page
		start = len(choices) - pageSize
		end = len(choices)
		cursor = sel - start

	} else {
		// somewhere in the middle
		above := pageSize / 2
		below := pageSize - above

		cursor = pageSize / 2
		start = sel - above
		end = sel + below
	}

	// return the subset we care about and the index
	return choices[start:end], cursor
}
1356433
func (ps pageStatePages) findPagePos(page *pageState) int {
	for i, x := range ps {
		if x.File().Filename() == page.File().Filename() {
			return i
		}
	}
	return -1
}
931779
func paginationQuery(options *ListOptions) string {
	query := url.Values{}
	query.Set("limit", strconv.Itoa(options.Limit))
	query.Set("offset", strconv.Itoa(options.Offset))

	return query.Encode()
}