Skip to content Search Apps Documentation Source Content File Folder Download Copy Actions State String Boolean Number Struct Map Slice Pointer Function Closure Reference Nil Package Type Interface Unknown

Community realm. Read the code first. Community realm, deployed by its author. Read the code before you interact or send coins.

v0 source pure

Package pageable implements a flexible pagination system that can be used with any data structure that implements the...

Readme View source

gno.land/p/moul/pageable

Pagination for anything that can hand out a window of its items, plus the Markdown page picker to navigate it.

Implement one method and you get pages, page sizes, reverse order, URL query parsing and a rendered picker:

1type Pageable interface {
2	Size() int
3	IterateByOffset(offset, count int, cb func(index, value interface{}) bool) bool
4}

Note the single IterateByOffset. Some structures expose separate forward and reverse iteration; this interface deliberately does not. Direction is carried by the sign of count (offset 0 count 5 gives items 0..4; offset 0 count -5 gives 4..0), and the implementation handles it internally, so the pager has one code path instead of two.

Use

1pager := pageable.NewPager(source, 10 /* default page size */, false /* reversed */)
2
3page := pager.MustGetPageByPath(path)   // reads ?page= and ?size= from the path
4out := ""
5for _, item := range page.Items {
6	out += "- " + item.Value.(string) + "\n"   // Item is {Index, Value interface{}}
7}
8out += page.Picker()                    // "1 | **2** | 3 | ..." as Markdown links

GetPageByPath returns an error instead of panicking; MustGetPageByPath is the Render-side shorthand. PickerWithPath(path) preserves the other query parameters (everything but page), which is what you want when the realm has its own filters in the URL.

GetPage(n) and GetPageWithSize(n, size) skip URL parsing entirely.

Page also carries TotalItems, TotalPages, HasPrev and HasNext, so a realm can render its own navigation instead of using Picker().

Nothing imports it

The package doc claims two consumers, p/nt/avl/pager and p/moul/ulist/pager. Neither holds today: the upstream p/nt/avl/pager is a standalone AVL pager that does not import this interface, and p/moul/ulist/pager does not exist in this repository (p/moul/ulist ships lplist, not a pager). Grepping this repo, the only files mentioning pageable are its own source and test.

So treat it as a proposed interface with a working reference implementation and a 410-line test, not as load-bearing code. The package doc comment has been corrected to say so.


Part of moul/gno-contracts — moul's versioned gno.land contracts. See the repository for the full catalog, build/test tooling, and usage.

Dependency graph:

gno.land/p/moul/pageable/v0 dependency graph

⚠️ Disclaimer: provided as-is, without warranty; not security-audited. Full disclaimer: DISCLAIMER.

Overview

Package pageable implements a flexible pagination system that can be used with any data structure that implements the Pageable interface. It provides functionality for:

  • Paginating through collections of items
  • Configurable page sizes
  • Forward and reverse iteration
  • URL query parameter parsing
  • Markdown-based pagination UI

Nothing imports it yet. An earlier version of this comment named gno.land/p/nt/avl/pager and gno.land/p/moul/ulist/pager as consumers; neither is one. The upstream avl pager is a standalone implementation that does not go through this interface, and ulist ships lplist, not a pager. Treat this as a proposed interface with a reference Pager and a test, not as load-bearing code.

Functions 1

func NewPager

1func NewPager(source Pageable, defaultPageSize int, reversed bool) *Pager
source

NewPager creates a new Pager with default values

Types 4

type Item

struct
1type Item struct {
2	Index interface{}
3	Value interface{}
4}
source

Item represents a generic item in the page

type Page

struct
 1type Page struct {
 2	Items      []Item
 3	PageNumber int
 4	PageSize   int
 5	TotalItems int
 6	TotalPages int
 7	HasPrev    bool
 8	HasNext    bool
 9	Pager      *Pager
10}
source

Page represents a single page of results

Methods on Page

func Picker

method on Page
1func (p *Page) Picker() string
source

Picker generates the Markdown UI for the page picker using default query string format

func PickerWithPath

method on Page
1func (p *Page) PickerWithPath(path string) string
source

PickerWithPath generates the Markdown UI for the page picker with optional path If path is provided, it preserves existing query parameters (except page)

type Pageable

interface
 1type Pageable interface {
 2	// Size returns the total number of items
 3	Size() int
 4
 5	// IterateByOffset performs iteration starting from offset for count elements.
 6	// The callback receives an index and a value, returns true to stop iteration.
 7	//
 8	// For reverse iteration, the implementation should handle the direction internally
 9	// by adjusting how it interprets the offset and count parameters. For example:
10	// - In forward mode: offset 0, count 5 would return items [0,1,2,3,4]
11	// - In reverse mode: offset 0, count -5 would return items [4,3,2,1,0]
12	//
13	// This approach allows the interface to remain simple while supporting
14	// bidirectional iteration through the implementation layer.
15	IterateByOffset(offset int, count int, cb func(index interface{}, value interface{}) bool) bool
16}
source

Pageable defines the minimal interface required for pagination. This interface is intentionally lightweight, requiring only two methods. While some data structures (like AVL trees) might have separate methods for forward and reverse iteration, this interface consolidates both directions into a single IterateByOffset method. It's the responsibility of the implementing wrapper to handle the direction logic internally based on the offset and count parameters.

type Pager

struct
1type Pager struct {
2	Source          Pageable
3	PageQueryParam  string
4	SizeQueryParam  string
5	DefaultPageSize int
6	Reversed        bool
7}
source

Pager provides pagination functionality for any Pageable source

Methods on Pager

func GetPage

method on Pager
1func (p *Pager) GetPage(pageNumber int) *Page
source

GetPage retrieves a page of results from the AVL tree.

func GetPageByPath

method on Pager
1func (p *Pager) GetPageByPath(rawURL string) (*Page, error)
source

GetPageByPath retrieves a page of results based on the query parameters in the URL path.

func GetPageWithSize

method on Pager
1func (p *Pager) GetPageWithSize(pageNumber, pageSize int) *Page
source

func ParseQuery

method on Pager
1func (p *Pager) ParseQuery(rawURL string) (int, int, error)
source

Dependencies

Imports 4

/p/g1magld5ptgzaktqcexxq0pgq5lmdf0kz6re8hlv/pageable/v0

Imported by indexer

Source Files 4