pagination

package module
v0.0.0-...-4cb57f5 Latest Latest
Warning

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

Go to latest
Published: Apr 23, 2017 License: MIT, Apache-2.0 Imports: 6 Imported by: 1

README

wercker status

Pagination Over Martini

Simple service to create pagination GET REST API quickly. Uses 'render' martini contrib package.

Example:

using GORM

import "github.com/shlomomatichin/go-martini-paginition"

func ListOrganizationsView(p *pagination.Pagination, db gorm.DB) {
	var organizations []Organization
    var count unit64
	db.Offset(p.Offset).Limit(p.PerPage).Find(&organizations).Count(&count)
    p.SetTotal(count)
	for _, organization := range organizations {
		organizationJSON := map[string]interface{}{
			"Id":   organization.Id,
			"Name": organization.Name,
			"Center": map[string]interface{}{
				"Longitude": organization.CenterLongitude,
				"Latitude":  organization.CenterLatitude,
			},
		}
        p.Append(organizationJSON);
	}
}

func RegisterOrganizationRESTViews(m *martini.ClassicMartini) {
	m.Get("/api/v1/organization", RoleAllowed(), pagination.Service, ListOrganizationsView)
}

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DefaultPerPage uint = 20

Functions

func Service

func Service(c martini.Context, req *http.Request, r render.Render)

Types

type Pagination

type Pagination struct {
	Page     uint
	Offset   uint
	PerPage  uint
	Bookmark string
	// contains filtered or unexported fields
}

func (*Pagination) Append

func (pagination *Pagination) Append(obj interface{})

func (*Pagination) IsAborted

func (pagination *Pagination) IsAborted() bool

func (*Pagination) SetAbort

func (pagination *Pagination) SetAbort()

func (*Pagination) SetNextBookmark

func (pagination *Pagination) SetNextBookmark(offset uint, bookmark string)

func (*Pagination) SetTotal

func (pagination *Pagination) SetTotal(total uint)

Jump to

Keyboard shortcuts

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