-
Notifications
You must be signed in to change notification settings - Fork 26
/
pagination.go
30 lines (25 loc) · 953 Bytes
/
pagination.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
package kumex
import (
"github.com/json-iterator/go"
)
// A PaginationParam represents the pagination parameters `currentPage` `pageSize` in a request .
type PaginationParam struct {
CurrentPage int64
PageSize int64
}
// ReadParam read pagination parameters into params.
func (p *PaginationParam) ReadParam(params map[string]string) {
params["currentPage"], params["pageSize"] = IntToString(p.CurrentPage), IntToString(p.PageSize)
}
// A PaginationModel represents the pagination in a response.
type PaginationModel struct {
CurrentPage int64 `json:"currentPage"`
PageSize int64 `json:"pageSize"`
TotalNum int64 `json:"totalNum"`
TotalPage int64 `json:"totalPage"`
RawItems jsoniter.RawMessage `json:"items"` // delay parsing
}
// ReadItems read the `items` into v.
func (p *PaginationModel) ReadItems(v interface{}) error {
return jsoniter.Unmarshal(p.RawItems, v)
}