https://github.com/xusenlin/gin-pagination
gin-pagination
https://github.com/xusenlin/gin-pagination
Last synced: 5 months ago
JSON representation
gin-pagination
- Host: GitHub
- URL: https://github.com/xusenlin/gin-pagination
- Owner: xusenlin
- Created: 2023-11-27T02:11:15.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2023-12-06T07:30:07.000Z (over 2 years ago)
- Last Synced: 2023-12-07T08:04:08.957Z (over 2 years ago)
- Language: Go
- Size: 9.77 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# gin-pagination
Pagination for Gin and Gorm
## Install
```
go get github.com/xusenlin/gin-pagination@v0.0.3-alpha
```
## Usage
### init
```golang
import (
ginPagination "github.com/xusenlin/gin-pagination"
)
//...Conn is *gorm.DB
ginPagination.Init(&ginPagination.Config{
PageSizeMaxVal: 100,
PageSizeDefaultVal: 20,
DB: Conn,
})
```
### pagination
```golang
func Find(c *gin.Context) {
model := new(User)
pagination := ginPagination.New[*User](model, c)
pagination.Like("name").Eq("id") //...more
err := pagination.Query()
if err != nil {
tools.SendErrJson(c, err)
return
}
for idx := range pagination.List {
pagination.List[idx].Password = "***"
}
tools.SendOkJson(c, "search successful", pagination)
}
```
## Pagination struct
```golang
type Pagination[T any] struct {
List []T `json:"list"`
Total int64 `json:"total"`
PageNum int `json:"pageNum"`
PageSize int `json:"pageSize"`
TotalPage int `json:"totalPage"`
query *gorm.DB
ctx *gin.Context
}
```