mygo_pagination

package module
v0.0.0-...-0a153b8 Latest Latest
Warning

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

Go to latest
Published: Sep 29, 2017 License: Apache-2.0 Imports: 2 Imported by: 6

README

MyGO Pagination

this unity for generator page number for golang

  • if you using gorm & gin
type MyInput struct {
  Pagging
}

func Query(c *gin.Context) {  
  inputs := MyInput{}
  if err := c.Bing(); err != nil {
    c.JSON(400, err.Error())
  }
  q := db.Table("mytable").Where("id > 10")
  pg := inputs.Pagging(q)
  q.Offset(pg.Offset).Limit(pg.Limit)
}
  • if you use other go web / orm
pagging := Pagging{
  Limit: 10
  Page: 1
}

// get total by your sql code
pg := pagging.PageInfoGenerator(total)

// You will get toal / total_page / offset / limit

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Pagging

type Pagging struct {
	//number of reacord's limit on each page
	Limit int `json:"limit" form:"limit"`
	//pagging
	Page int `json:"page" form:"page"`
}

func (Pagging) GenOffset

func (inputs Pagging) GenOffset(query *gorm.DB) (pg PaggingInfo, err error)

func (Pagging) PageInfoGenerator

func (inputs Pagging) PageInfoGenerator(total int) (pg PaggingInfo)

type PaggingInfo

type PaggingInfo struct {
	TotalRecord int `json:"total_record"`
	TotalPage   int `json:"total_page"`
	Offset      int `json:"offset"`
	Limit       int `json:"limit"`
	Page        int `json:"page:"`
}

Jump to

Keyboard shortcuts

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