Help us shape the future of Go! Take the 2026 Go Developer Survey

paginator

package module
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Apr 7, 2026 License: MPL-2.0 Imports: 3 Imported by: 4

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	DefaultPaginator = Paginator{
		Page:     1,
		PageSize: defaultPageSize,
		Offset:   0,
	}
)

Functions

func GetLimitFromListParam added in v0.0.2

func GetLimitFromListParam[T Integer](list ...*protobuf.ListParam) (T, T)

GetLimitFromListParam 从protobuf.ListParam转换成Offset, PageSize

func GetStartEndPosition

func GetStartEndPosition(page, pageSize, total int64) (int64, int64)

GetStartEndPosition 如果是按列表slice进行翻页的话, 计算slice的起始index

func Paginate

func Paginate[T any](sliceVars []T, pageSize int64) [][]T

Paginate 分页

Types

type Integer added in v0.0.2

type Integer interface {
	~int | ~int32 | ~int64
}

type Page

type Page struct {
	Start int64
	End   int64
}

func CalculatePages

func CalculatePages(total, pageSize int64) []Page

CalculatePages 根据总数量和每页多少个计算Page数组

type Paginator

type Paginator struct {
	Page     uint64 // 第几页
	PageSize uint64 // 每页的大小
	Offset   uint64 // 偏移起始值
}

func New

func New[T Integer](page, pageSize T) Paginator

New 获取分页器

func NewFromListParam added in v0.0.2

func NewFromListParam(list ...*protobuf.ListParam) Paginator

func (Paginator) GetSQLLimitClause added in v0.0.2

func (p Paginator) GetSQLLimitClause() string

GetSQLLimitClause 获取SQL的limit子句

type UtilsPaginator

type UtilsPaginator interface {
	GetSQLLimitClause() string
}

Jump to

Keyboard shortcuts

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