paginator

package
v1.1.2 Latest Latest
Warning

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

Go to latest
Published: Sep 19, 2022 License: Apache-2.0 Imports: 1 Imported by: 0

README

数据分页工具

工具加载

import (
	"github.com/cnlesscode/gotool/paginator"
)

相关说明

1. 核心方法 paginator.Run
2. 返回值格式
type Pager struct {
	// 分页列表
	Pages       []int
	// 分页总数
	TotalPages  int
	// 首页
	FirstPage   int
	// 尾页
	PrePage     int
	// 下一页
	NextPage    int
	// 最后一页
	Lastpage    int
	// 当前页
	CurrentPage int
}
3. 不需要展示的数据 对应值为 -1,前端可以利用此条件决定是否展示

分页示例

package main

import (
	"fmt"

	"github.com/cnlesscode/gotool/paginator"
)

type Person struct {
	Name string
	Age  int
}

func main() {
	pager := paginator.Run(98, 1, 100, 10)
	fmt.Printf("CurrentPage: %v\n", pager.CurrentPage)
	fmt.Printf("FirstPage: %v\n", pager.FirstPage)
	fmt.Printf("PrePage: %v\n", pager.PrePage)
	fmt.Printf("Pages: %v\n", pager.Pages)
	fmt.Printf("NextPage: %v\n", pager.NextPage)
	fmt.Printf("Lastpage: %v\n", pager.Lastpage)
	fmt.Printf("TotalPages: %v\n", pager.TotalPages)
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Pager

type Pager struct {
	Pages       []int
	TotalPages  int
	FirstPage   int
	PrePage     int
	NextPage    int
	Lastpage    int
	CurrentPage int
}

func Run

func Run(currentPage, everyPageNumber, total int, pagesNumber int) Pager

Jump to

Keyboard shortcuts

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