Skip to content

Latest commit

 

History

History
41 lines (28 loc) · 784 Bytes

README.md

File metadata and controls

41 lines (28 loc) · 784 Bytes

Paginator

This intends to be a plugin for paginating golang.

Currently only supports gorm.

Install

go get -u github.com/Prabandham/paginator

Usage.

p import github.com/Prabandham/paginator


type User struct{

    gorm.Model

    Name string
    .
    .
    .
}

func FindAllUsers() []User {
    var users  []User
    db, err := gorm.Open("postgres", ....)
    order_by := []string{"name asc"}
    paginator := p.Paginator{DB: &db, OrderBy: order_by, Page: "1", PerPage: "10"}
    data := paginator.Paginate(&users)

    //data -> {
    //          total_records: 1000,
    //          records: [{Name: "Srinidhi"}, {Name: "Prabandham"},...],
    //          current_page: 1,
    //          total_pages: 100
    //        }
}