Skip to content

Pagination Service for JSON REST apis implementation in martini/go

License

MIT, Apache-2.0 licenses found

Licenses found

MIT
LICENSE
Apache-2.0
LICENSE.txt
Notifications You must be signed in to change notification settings

shlomimatichin/go-martini-pagination

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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)
}

About

Pagination Service for JSON REST apis implementation in martini/go

Resources

License

MIT, Apache-2.0 licenses found

Licenses found

MIT
LICENSE
Apache-2.0
LICENSE.txt

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages