pages

package
v0.0.0-...-8170b65 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 25, 2023 License: Apache-2.0 Imports: 0 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ManmadePage

func ManmadePage(pager Pager, page Page) (Pager, Page)

ManmadePage 手动分页,这里用泛型写更好,我是1.16的,就不用泛型改interface类型了

func manmadePage[T any](items []T, page Page) ([]T, Page) {
	if len(items) == 0 {
		return nil, page.Clone(0)
	}
	pg := page.Clone(len(items))
	start, end := pg.GetStartAndEnd()
	items = items[start:end]
	return items, pg
}

Types

type Page

type Page struct {
	PageIndex  int `json:"pageIndex,omitempty" form:"pageIndex"` // 页码
	PageSize   int `json:"pageSize,omitempty" form:"pageSize"`   // 每页条数
	TotalCount int `json:"totalCount,omitempty"`                 // 总数
}

func (Page) Clone

func (p Page) Clone(totalCount int) Page

func (Page) GetStartAndEnd

func (p Page) GetStartAndEnd() (start, end int)

func (Page) PageOffsetAndLimit

func (p Page) PageOffsetAndLimit() (int, int)

PageOffsetAndLimit pageIndex transfer pageOffset

func (*Page) SetPage

func (p *Page) SetPage(index, size, count int)

type Pager

type Pager interface {
	Len() int
	Copy(start, end int)
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL