opqcursor

package
v1.5.0 Latest Latest
Warning

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

Go to latest
Published: May 7, 2024 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Marshal

func Marshal[Filters any, Sorters any](filters Filters, sorters Sorters) (string, error)

Marshal encodes the OpaqueCursor struct and returns the cursor string.

Types

type OpaqueCursor

type OpaqueCursor[F any, S any] struct {
	Filters F `json:"filters"`
	Sorters S `json:"sorters"`
}

OpaqueCursor is a struct that contains the filters and sorters for a query. Generally used in GraphQL based APIs to pass the cursor as a string. But the scenarios are not limited to GraphQL only, you could use it in any API that requires a cursor.

func Unmarshal

func Unmarshal[Filters any, Sorters any](cursor string) (*OpaqueCursor[Filters, Sorters], error)

Unmarshal decodes the cursor string and returns the OpaqueCursor struct.

func UnmarshalWithDefaults

func UnmarshalWithDefaults[Filters any, Sorters any](cursor string, defaults OpaqueCursor[Filters, Sorters]) (*OpaqueCursor[Filters, Sorters], error)

UnmarshalWithDefaults decodes the cursor string and returns the OpaqueCursor struct with defaults additionally.

func (OpaqueCursor[F, S]) IsValid

func (oc OpaqueCursor[F, S]) IsValid() bool

IsValid checks if the cursor is valid or not. It checks if the sorters are valid or not.

NOTICE: currently the sorters are checked for ASC and DESC only.

Jump to

Keyboard shortcuts

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