Skip to content

hapoon/gopager

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

gopager

GoDoc Build Status Coverage Status Go Report Card MIT License

gopager is a library for pagination.

Installation

Make sure that Go is installed on your computer. Type the following command in your terminal:

go get github.com/hapoon/gopager

After it the package is ready to use.

Add following line in your *.go file:

import "github.com/hapoon/gopager"

Usage

You need to implement the Pageable interface for slices to use paging. Len() returns the length of slices.

type Item struct {
    ID uint
}

type Items []Item

func (i Items) Len() int {
    return len(i)
}
items := Items{
    Item{ID: 1},
    Item{ID: 2},
    Item{ID: 3},
    Item{ID: 4},
    Item{ID: 5},
}
pageSize := 2

p := gopager.NewPaginater(items,pageSize)

i := Items{}
for p.HasNext() {
    p.Next(&i)
    fmt.Printf("Page: %v i: %v\n",p.CurrentPage(),i)
}

Output:

Page: 1 i: [{ID:1} {ID:2}]
Page: 2 i: [{ID:3} {ID:4}]
Page: 3 i: [{ID:5}]

License

MIT License

About

A pagination library for go language.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published