pagination

package
v1.8.6 Latest Latest
Warning

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

Go to latest
Published: Apr 4, 2024 License: Apache-2.0 Imports: 0 Imported by: 0

Documentation

Overview

Package pagination provides a simple pagination inteface for ordered items with string IDs.

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Pageable

type Pageable interface {
	// ExtractID derives an identifier that is guaranteed to be unique relative
	// to any elements with which it may coexist in a given collection
	ExtractID() string
}

Pageable is an type that can be paginated when present in a collection.

Example
package main

import (
	"fmt"
)

type Thing string

func (o Thing) ExtractID() string {
	return string(o)
}

func main() {
	pages := []Pageable{
		Thing("foo"),
		Thing("bar"),
		Thing("baz"),
		Thing("boo"),
		Thing("bla"),
	}

	page := GetPageAfterID(pages, "bar", 2)
	fmt.Printf("%v", page)
}
Output:

[baz boo]

func GetPageAfterID

func GetPageAfterID(
	elements []Pageable,
	after string,
	pageSize uint,
) []Pageable

GetPageAfterID paginates elements. The first element of the returned page directly follows the element in elements having an ID equivalent to after. At most pageSize results are included in the returned page.

Jump to

Keyboard shortcuts

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