Documentation ¶
Overview ¶
Package pager Paging tool
pager.New(ctx, driver).SetIndex(c.entity.TableName()).Find(c.entity).Result()
Index ¶
- func ParseSkip(request *http.Request) int
- func StringToBool(val interface{}) interface{}
- func StringToFloat32(val interface{}) interface{}
- func StringToFloat64(val interface{}) interface{}
- func StringToInt(val interface{}) interface{}
- type Driver
- type FilterKey
- type Int64Slice
- type Pagination
- func (pagination *Pagination) AddDisableField(fields ...string) *Pagination
- func (pagination *Pagination) AddFilterKeyMapping(key, column string) *Pagination
- func (pagination *Pagination) Find(structure interface{}) *Pagination
- func (pagination *Pagination) Limit(limit int) *Pagination
- func (pagination *Pagination) ParseRange() Range
- func (pagination *Pagination) ParsingLimit() int
- func (pagination *Pagination) ParsingQuery() Where
- func (pagination *Pagination) Range(r Range) *Pagination
- func (pagination *Pagination) Result() *Result
- func (pagination *Pagination) SetFilterKey(key FilterKey) *Pagination
- func (pagination *Pagination) SetIndex(index string) *Pagination
- func (pagination *Pagination) SetPaginationField(field string) *Pagination
- func (pagination *Pagination) Sort(kv []SortInfo) *Pagination
- func (pagination *Pagination) Where(kv Where) *Pagination
- type Range
- type RangeKey
- type RangeType
- type Result
- type Sort
- type SortInfo
- type Where
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func StringToBool ¶
func StringToBool(val interface{}) interface{}
StringToBool convert string to bool
func StringToFloat32 ¶
func StringToFloat32(val interface{}) interface{}
StringToFloat32 convert string to float32
In fact, if the string type data is not passed in, then the int32 type data will not be returned here, but the original data will be returned.
func StringToFloat64 ¶
func StringToFloat64(val interface{}) interface{}
StringToFloat64 convert string to float64
In fact, if the string type data is not passed in, then the float64 type data will not be returned here, but the original data will be returned.
func StringToInt ¶
func StringToInt(val interface{}) interface{}
StringToInt convert string to int
In fact, if the string type data is not passed in, then the int type data will not be returned here, but the original data will be returned.
Types ¶
type Driver ¶
type Driver interface { // Set filter conditions Where(kv Where) // Set range query conditions Range(r Range) // Set the limit per page Limit(limit int) // Set the number of skips Skip(skip int) // Index Index name, which can be a table name, or, for example, the index name of es, something that identifies a specific collection of resources Index(index string) // 排序 Sort(kv []SortInfo) // Query operation, driver, it is recommended to perform real data scanning in this method to save performance Find(data interface{}) // If the data structure passed by the Find method needs to be analyzed in the implementation code of the specific driver, // this method will be called and passed in the data reflection type. For example, in mongo, // the construction of the query language has strict requirements on the type. Here, // the reflection Type of the data type will be passed in to drive the driver to analyze the record data type and convert the filtered data passed in by Where. SetTyp(typ reflect.Type) // Calculate the total number of qualified data items according to all filter conditions Count() int64 }
Driver Data query driver, Pagination will pass the parsed parameters to it. Theoretically, any driver that implements this interface can call this package to achieve the general paging function.
type FilterKey ¶
type FilterKey struct { // page parameter name Page string // rows parameter name Rows string // sorts parameter name Sorts string // range parameter name Range string }
FilterKey Custom name of the parameter carried by url
type Int64Slice ¶
type Int64Slice []int64
Int64Slice int64 sort
func (Int64Slice) Len ¶
func (p Int64Slice) Len() int
func (Int64Slice) Less ¶
func (p Int64Slice) Less(i, j int) bool
func (Int64Slice) Swap ¶
func (p Int64Slice) Swap(i, j int)
type Pagination ¶
type Pagination struct {
// contains filtered or unexported fields
}
Pagination page tool
func (*Pagination) AddDisableField ¶
func (pagination *Pagination) AddDisableField(fields ...string) *Pagination
AddDisableField add fields that are prohibited from participating in search filtering
func (*Pagination) AddFilterKeyMapping ¶
func (pagination *Pagination) AddFilterKeyMapping(key, column string) *Pagination
AddFilterKeyMapping filter condition mapping. If the key carried by url is different from the field name of the database, set it here
func (*Pagination) Find ¶
func (pagination *Pagination) Find(structure interface{}) *Pagination
Find use driver to query data
structure the structure of the data, without the need for a pointer
func (*Pagination) Limit ¶
func (pagination *Pagination) Limit(limit int) *Pagination
Limit set the default number of data items returned per page
func (*Pagination) ParsingLimit ¶
func (pagination *Pagination) ParsingLimit() int
ParsingLimit Parse the number of entries displayed per page from the http request
func (*Pagination) ParsingQuery ¶
func (pagination *Pagination) ParsingQuery() Where
ParsingQuery Parse the filter condition from the http request
func (*Pagination) Range ¶
func (pagination *Pagination) Range(r Range) *Pagination
Range specify range query parameters
func (*Pagination) SetFilterKey ¶
func (pagination *Pagination) SetFilterKey(key FilterKey) *Pagination
SetFilterKey custom paging related query parameters
func (*Pagination) SetIndex ¶
func (pagination *Pagination) SetIndex(index string) *Pagination
SetIndex set the collection or table name in the query driver, for example, the database is the table name
func (*Pagination) SetPaginationField ¶
func (pagination *Pagination) SetPaginationField(field string) *Pagination
SetPaginationField when this value is set, the next_id in the returned data will be equal to the field value of the last element in slice, and prev_id will be equal to the field value of the first element in slice
func (*Pagination) Sort ¶
func (pagination *Pagination) Sort(kv []SortInfo) *Pagination
Sort specify sort
func (*Pagination) Where ¶
func (pagination *Pagination) Where(kv Where) *Pagination
Where set default query parameters, such as returning only the user's own browsing log after the user logs in, which is valid throughout the life cycle of the object.
type RangeType ¶
type RangeType int
RangeType Types
Gte: Greater than or equal to Lte: Less than or equal to
type Result ¶
type Result struct { Data interface{} `json:"data" xml:"data"` // data slice NextID interface{} `json:"next_id" xml:"next_id"` // next page id PrevID interface{} `json:"prev_id" xml:"prev_id"` // prev page id Count int64 `json:"count" xml:"count"` // number of qualified data items according to all filter conditions Rows int `json:"rows" xml:"rows"` // Display the number of entries per page }
Result Result Object