page

package
v1.1.3 Latest Latest
Warning

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

Go to latest
Published: Aug 29, 2024 License: Apache-2.0 Imports: 4 Imported by: 1

README

分页组件

如何使用

引用PB
syntax = "proto3";

import "servicecommon/page/page.proto";

package did;
option go_package="./serviceexample";

message VcPageRequest {
  page.Page page = 1;
  string did = 2;
  int32 status = 3;
}

message VcPageResponse {
  int32 code = 1;
  string msg = 2;
  VcPageResponseData data = 3;
}

message VcPageResponseData {
  page.Page page = 1;
  repeated VcPageResponseDataItem list = 2;
}
主要功能
创建Page
func New(page, size int) *Page {
return &Page{Page: int32(page), Size_: int32(size)}
}
根据Page计算Offset
// Offset get mysql offset
func (p *Page) Offset() int {
return int((p.Page - 1) * p.Size_)
}

Documentation

Overview

Created by guoxin in 2024/1/7 11:47

Index

Constants

This section is empty.

Variables

View Source
var File_page_proto protoreflect.FileDescriptor

Functions

This section is empty.

Types

type Page

type Page struct {

	// 页数
	Page int32 `protobuf:"varint,1,opt,name=page,proto3" json:"page,omitempty,optional"`
	// 每页数据的条数
	Size int32 `protobuf:"varint,2,opt,name=size,proto3" json:"size,omitempty,optional"`
	// 总条数
	Total int64 `protobuf:"varint,3,opt,name=total,proto3" json:"total,omitempty,optional"`
	// contains filtered or unexported fields
}

分页对象,在请求和响应中使用该对象 eg:

{
  "code": 200,
  "msg": "ok",
  "data": {
    "page": {
      "page": 1,
      "size": 20,
      "total": 1000
    },
    "list": [
      data1...,
      data2...,
      dataN...
    ]
  }
}

}

func New

func New(page, size int) *Page

New Page

func (*Page) Descriptor deprecated

func (*Page) Descriptor() ([]byte, []int)

Deprecated: Use Page.ProtoReflect.Descriptor instead.

func (*Page) GetPage

func (x *Page) GetPage() int32

func (*Page) GetSize

func (x *Page) GetSize() int32

func (*Page) GetTotal

func (x *Page) GetTotal() int64

func (*Page) Limit

func (p *Page) Limit() int

Limit get limit

func (*Page) Offset

func (p *Page) Offset() int

Offset get mysql offset

func (*Page) ProtoMessage

func (*Page) ProtoMessage()

func (*Page) ProtoReflect

func (x *Page) ProtoReflect() protoreflect.Message

func (*Page) Reset

func (x *Page) Reset()

func (*Page) String

func (x *Page) String() string

Source Files

  • page.pb.go
  • tools.go

Jump to

Keyboard shortcuts

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