Documentation ¶
Index ¶
- Constants
- Variables
- func GenerateCursorURI(limit int64, cursor interface{}, options *Options) string
- func GenerateOffsetURI(limit int64, offset int64, options *Options) string
- func GetCursorFromRequest(request *http.Request, options *Options) int64
- func GetLimitFromRequest(request *http.Request, options *Options) int64
- func GetOffsetFromRequest(request *http.Request, options *Options) int64
- func GetPaginationType(request *http.Request, options *Options) string
- func ValidateLimitOffset(limit int64, offset int64) bool
- type CursorOptions
- type CursorPaginator
- func (c *CursorPaginator) HasNext() bool
- func (CursorPaginator) HasPrevious() bool
- func (p *CursorPaginator) MakeNextURI() null.String
- func (CursorPaginator) MakePreviousURI() null.String
- func (p *CursorPaginator) Next() (Paginator, error)
- func (p *CursorPaginator) Page() error
- func (p *CursorPaginator) Previous() (Paginator, error)
- type GORMStore
- type OffsetPaginator
- func (p *OffsetPaginator) HasNext() bool
- func (p *OffsetPaginator) HasPrevious() bool
- func (p *OffsetPaginator) MakeNextURI() null.String
- func (p *OffsetPaginator) MakePreviousURI() null.String
- func (p *OffsetPaginator) Next() (Paginator, error)
- func (p *OffsetPaginator) Page() error
- func (p *OffsetPaginator) Previous() (Paginator, error)
- type Options
- type Paginator
- type Store
Constants ¶
const ( OffsetType = "offset" CursorType = "cursor" )
pagination system type
const ( DateModeCursor = "dateCursor" IDModeCursor = "idCursor" )
cursor mode, date or id
const ( // DefaultLimit is the default number of items per page. DefaultLimit = 20 // DefaultLimitKeyName is the request key name. DefaultLimitKeyName = "limit" // DefaultOffsetKeyName is the request offset key name. DefaultOffsetKeyName = "offset" // DefaultCursorKeyName is the request cursor key name. DefaultCursorKeyName = "since" // DefaultCursorDBName is the default cursor db field name DefaultCursorDBName = "id" // DefaultCursorStructName is the default cursor struct field name DefaultCursorStructName = "ID" )
Variables ¶
var ErrInvalidLimitOrOffset = errors.New("invalid limit or offset")
ErrInvalidLimitOrOffset is returned by the OffsetPaginator's Page method to indicate that the limit or the offset is invalid
Functions ¶
func GenerateCursorURI ¶
GenerateCursorURI generates the pagination URI for cursor system.
func GenerateOffsetURI ¶
GenerateOffsetURI generates the pagination URI.
func GetCursorFromRequest ¶
GetCursorFromRequest returns current cursor.
func GetLimitFromRequest ¶
GetLimitFromRequest returns current limit.
func GetOffsetFromRequest ¶
GetOffsetFromRequest returns current offset.
func GetPaginationType ¶
GetPaginationType returns the pagination type "offeset|cursor" (use constant CursorType or OffsetType) return OffsetType by default
func ValidateLimitOffset ¶
ValidateLimitOffset returns true if limit and offset values are valid
Types ¶
type CursorOptions ¶
type CursorOptions struct { // Mode set type of cursor, an ID or a Date (time.Time) Mode string // KeyName is the query string key name for the cursor KeyName string // DBName is the cursor's database column name DBName string // StructName is the cursor struct field name StructName string // Reverse turn true to work with DESC request Reverse bool }
CursorOptions group all options about cursor pagination
type CursorPaginator ¶
type CursorPaginator struct { Cursor interface{} `json:"-"` PreviousURI null.String `json:"-"` // contains filtered or unexported fields }
CursorPaginator is the paginator with cursor pagination system.
func NewCursorPaginator ¶
func NewCursorPaginator(store Store, request *http.Request, options *Options) (*CursorPaginator, error)
NewCursorPaginator returns a new CursorPaginator instance.
func (*CursorPaginator) HasNext ¶
func (c *CursorPaginator) HasNext() bool
HasNext returns true if has next page.
func (CursorPaginator) HasPrevious ¶
func (CursorPaginator) HasPrevious() bool
HasPrevious returns false, previous page is not available on cursor system
func (*CursorPaginator) MakeNextURI ¶
func (p *CursorPaginator) MakeNextURI() null.String
MakeNextURI returns the next page URI.
func (CursorPaginator) MakePreviousURI ¶
func (CursorPaginator) MakePreviousURI() null.String
MakePreviousURI returns an empty URI.
func (*CursorPaginator) Next ¶
func (p *CursorPaginator) Next() (Paginator, error)
Next returns next items
func (*CursorPaginator) Page ¶
func (p *CursorPaginator) Page() error
Page searches and returns the items
func (*CursorPaginator) Previous ¶
func (p *CursorPaginator) Previous() (Paginator, error)
Previous is not available on cursor system
type GORMStore ¶
type GORMStore struct {
// contains filtered or unexported fields
}
GORMStore is the store for GORM ORM.
func NewGORMStore ¶
NewGORMStore returns a new GORM store instance.
func (*GORMStore) GetItems ¶
func (s *GORMStore) GetItems() interface{}
GetItems return the current result
type OffsetPaginator ¶
type OffsetPaginator struct { Offset int64 `json:"offset"` Count int64 `json:"total_count"` PreviousURI null.String `json:"previous"` // contains filtered or unexported fields }
OffsetPaginator is the paginator with offset pagination system.
func NewOffsetPaginator ¶
func NewOffsetPaginator(store Store, request *http.Request, options *Options) (*OffsetPaginator, error)
NewOffsetPaginator returns a new OffsetPaginator instance.
func (*OffsetPaginator) HasNext ¶
func (p *OffsetPaginator) HasNext() bool
HasNext returns true if has next page.
func (*OffsetPaginator) HasPrevious ¶
func (p *OffsetPaginator) HasPrevious() bool
HasPrevious returns true if there is a previous page.
func (*OffsetPaginator) MakeNextURI ¶
func (p *OffsetPaginator) MakeNextURI() null.String
MakeNextURI returns the next page URI.
func (*OffsetPaginator) MakePreviousURI ¶
func (p *OffsetPaginator) MakePreviousURI() null.String
MakePreviousURI returns the previous page URI.
func (*OffsetPaginator) Next ¶
func (p *OffsetPaginator) Next() (Paginator, error)
Next returns next items
func (*OffsetPaginator) Page ¶
func (p *OffsetPaginator) Page() error
Page searches and returns the items
func (*OffsetPaginator) Previous ¶
func (p *OffsetPaginator) Previous() (Paginator, error)
Previous returns previous items
type Options ¶
type Options struct { // DefaultLimit is the default number of items per page DefaultLimit int64 // MaxLimit is the maximum limit that can be set MaxLimit int64 // LimitKeyName is the query string key name for the limit LimitKeyName string // OffsetKeyName is the query string key name for the offset OffsetKeyName string // CursorOptions CursorOptions *CursorOptions }
Options are paginator options