resource

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jul 24, 2023 License: MPL-2.0 Imports: 4 Imported by: 0

Documentation

Overview

Package resource contains code common to all resources (orgs, workspaces, runs, etc)

Index

Constants

View Source
const (
	DefaultPageNumber = 1
	DefaultPageSize   = 20
	MaxPageSize       = 100
)

Variables

This section is empty.

Functions

func ListAll

func ListAll[T any](fn func(PageOptions) (*Page[T], error)) ([]T, error)

ListAll is a helper for retrieving all pages. The provided fn should perform an operation that retrieves a page at a time.

Types

type Page

type Page[T any] struct {
	Items []T
	*Pagination
}

Page is a segment of a result set.

func NewPage

func NewPage[T any](resources []T, opts PageOptions, count *int64) *Page[T]

NewPage constructs a page from a list of resources. If the list argument represents the full result set then count should be nil; if count is non-nil then the list is deemed to be a segment of a result set and count is the size of the full result set. This latter case is useful, say, if a database has already produced a segment of a full result set, e.g. using LIMIT and OFFSET.

type PageOptions

type PageOptions struct {
	// The page number to request. The results vary based on the PageSize.
	PageNumber int `schema:"page[number],omitempty"`
	// The number of elements returned in a single page.
	PageSize int `schema:"page[size],omitempty"`
}

PageOptions are used to request a specific page.

func (PageOptions) GetLimit

func (o PageOptions) GetLimit() pgtype.Int8

GetLimit calculates the limit for use in SQL queries.

func (PageOptions) GetOffset

func (o PageOptions) GetOffset() pgtype.Int8

GetOffset calculates the offset for use in SQL queries.

type Pagination

type Pagination struct {
	CurrentPage  int  `json:"current-page"`
	PreviousPage *int `json:"prev-page"`
	NextPage     *int `json:"next-page"`
	TotalPages   int  `json:"total-pages"`
	TotalCount   int  `json:"total-count"`
}

Pagination provides metadata about a page.

Jump to

Keyboard shortcuts

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