page

package
v0.6.0 Latest Latest
Warning

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

Go to latest
Published: Oct 24, 2024 License: MIT Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewContReader

func NewContReader(args NewContReaderArgs) core.Reader[Page]

NewContReader passes ints from args.Reader to NewOnceReader, from which pages are returned here. When all pages are read, a new int from args.Reader is passed to a new NewOnceReader, and so on.

Examples (interactive):

func NewContWriter

func NewContWriter[T any](args NewContWriterArgs[T]) core.Writer[T]

NewContWriter returns a writer which writes values to args.Writer along with pagination directives coming from an internal NewContReader made with args.Reader and args.Limit.

Examples (interactive):

func NewOnceReader

func NewOnceReader(args NewOnceReaderArgs) core.Reader[Page]

NewOnceReader returns a Reader of pagination directives which supports paging from 0 to 'total' with the given 'limit', then returns an io.EOF. It is useful for e.g paging through a database if you know the total size.

Examples (interactive):

func NewOnceWriter

func NewOnceWriter[T any](args NewOnceWriterArgs[T]) core.Writer[T]

NewOnceWriter returns a writer which writes values to args.Writer along with pagination directives, based on args.Total and args.Limit, which are passed to NewOnceReader under the hood. When all pages are written, the writer returned here will give an io.ErrClosedPipe.

Examples (interactive):

Types

type NewContReaderArgs

type NewContReaderArgs struct {
	// Ints from here are passed as args.Total for NewOnceReader.
	Reader core.Reader[int]
	// Limit is passed to args.Limit for NewOnceReader.
	Limit int
}

type NewContWriterArgs

type NewContWriterArgs[T any] struct {
	Reader core.Reader[int]
	Writer core.Writer[Paged[T]]
	Limit  int
}

type NewOnceReaderArgs

type NewOnceReaderArgs struct {
	Total int
	Limit int
}

type NewOnceWriterArgs

type NewOnceWriterArgs[T any] struct {
	Writer core.Writer[Paged[T]]
	// Total is passed to NewOnceReader
	Total int
	// Limit is passed to NewOnceReader
	Limit int
}

type Page

type Page struct {
	Skip  int // Pagination skip.
	Limit int // Pagination limit.
	Total int // Total number of items.
}

Page represents pagination directives.

type Paged

type Paged[T any] struct {
	Page
	Val T
}

Paged is a wrapper of Page, containing a generic value.

Jump to

Keyboard shortcuts

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