Security News
Opengrep Emerges as Open Source Alternative Amid Semgrep Licensing Controversy
Opengrep forks Semgrep to preserve open source SAST in response to controversial licensing changes.
github.com/uptutu/pagination-go
简单的分页工具,只要结构体符合下面的要求,就可以使用该工具解析并填充。
PageNum
or Num
PageSize
or Size
OrderBy
IsDescending
or Descending
Qeury
or SearchKey
字段 type testRequest struct {
PageNum int
PageSize int
OrderBy string
IsDescending bool
KeyWords string
SearchKey string
CustomField string
}
Page
或 Pagination
的字段下
比如说这样:type SearchDialogCasesRequest struct {
Page *PaginationRequest
}
// pagination.pb.go
type PaginationRequest struct {
state protoimpl.MessageState
sizeCache protoimpl.SizeCache
unknownFields protoimpl.UnknownFields
PageNum int64 `protobuf:"varint,1,opt,name=page_num,json=pageNum,proto3" json:"page_num,omitempty"`
PageSize int64 `protobuf:"varint,2,opt,name=page_size,json=pageSize,proto3" json:"page_size,omitempty"`
OrderBy string `protobuf:"bytes,3,opt,name=order_by,json=orderBy,proto3" json:"order_by,omitempty"`
IsDescending bool `protobuf:"varint,4,opt,name=is_descending,json=isDescending,proto3" json:"is_descending,omitempty"`
SearchKey string `protobuf:"bytes,5,opt,name=search_key,json=searchKey,proto3" json:"search_key,omitempty"`
}
PageNum
, PageSize
和 Total
字段import "github.com/uptutu/pagination"
// 自定义请求结构体
type ListSubscribeEntitiesRequest {
PageNum int64
PageSize int64
OrderBy string
IsDescending bool
Query string
MyData interface{}
}
type ListSubscribeEntitiesResponse {
Total int64
PageNum int64
LastPage int64
PageSize int64
// 自己的数据
Data string
}
func (s *SubscribeService) ListSubscribeEntities(ctx context.Context, req *pb.ListSubscribeEntitiesRequest) (*pb.ListSubscribeEntitiesResponse, error) {
page, err := pagination.Parse(req)
//输出类似于 {Num:10 Size:50 OrderBy:test IsDescending:true SearchKey:"search"}
fmt.Println(page)
// returned Bool 判读是否需要分页
// return page_num > 0 && page_size > 0
page.Required()
// 返回限制个数(page_size)
page.Limit()
// 返回分页请求下标(page_num-1 * page_size)
page.Offset()
// 是否倒序
page.IsDescending
// 搜索关键字
page.Query
// 排序字段
page.OrderBy
// 获取总数
count := db.Find(data).Count()
// 请务必手动填充总数
page.SetTotal(count)
resp := &ListSubscribeEntitiesResponse{}
resp.Data = "一些数据"
// 此后 resp 的分页信息将会自动被填充
page.FillResponse(resp)
}
Used to determine if the paging request passed meets the paging needs
Judgement conditions:
func (p Page) Required() bool {
return p.Num > 0 && p.Size > 0
}
if no limit set this will return the default value.
func (p Page) Limit() int32 {
if p.Size != 0 {
return uint32(p.Size)
}
return uint32(p.defaultSize)
}
count the offset of the current page
func (p Page) Offset() int32 {
if p.Num <= 0 {
return 0
}
return uint32((p.Num - 1) * p.Size)
}
Automatic padding of paginated data to match paginated responsive design.
FAQs
Unknown package
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Opengrep forks Semgrep to preserve open source SAST in response to controversial licensing changes.
Security News
Critics call the Node.js EOL CVE a misuse of the system, sparking debate over CVE standards and the growing noise in vulnerability databases.
Security News
cURL and Go security teams are publicly rejecting CVSS as flawed for assessing vulnerabilities and are calling for more accurate, context-aware approaches.