cursor

package
v0.0.0-...-811544e Latest Latest
Warning

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

Go to latest
Published: Sep 25, 2024 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrInvalidCursor = errors.New("invalid cursor")
	ErrInvalidModel  = errors.New("invalid entity")
)

Functions

This section is empty.

Types

type Cursor

type Cursor struct {
	After  *string `json:"after" query:"after"`
	Before *string `json:"before" query:"before"`
}

Cursor cursor data

type CustomType

type CustomType interface {
	// GetCustomTypeValue returns the value corresponding to the meta attribute inside the custom type.
	GetCustomTypeValue(meta any) (any, error)
}

CustomType is an interface that custom types need to implement in order to allow pagination over fields inside custom types.

type Decoder

type Decoder struct {
	// contains filtered or unexported fields
}

Decoder cursor decoder

func NewDecoder

func NewDecoder(fields []DecoderField) *Decoder

NewDecoder creates cursor decoder for entity

func (*Decoder) Decode

func (d *Decoder) Decode(cursor string, model any) (fields []any, err error)

Decode decodes cursor into values (without pointer) by referencing field type on entity.

func (*Decoder) DecodeStruct

func (d *Decoder) DecodeStruct(cursor string, model any) (err error)

DecodeStruct decodes cursor into entity, entity must be a pointer to struct or it will panic.

type DecoderField

type DecoderField struct {
	Key  string
	Type *reflect.Type
}

DecoderField contains information about one decoder field.

type Encoder

type Encoder struct {
	// contains filtered or unexported fields
}

Encoder cursor encoder

func NewEncoder

func NewEncoder(fields []EncoderField) *Encoder

NewEncoder creates cursor encoder

func (*Encoder) Encode

func (e *Encoder) Encode(model any) (string, error)

Encode encodes entity into cursor

type EncoderField

type EncoderField struct {
	Key string
	// metas are needed for handling of custom types
	Meta any
}

EncoderField contains information about one encoder field.

Jump to

Keyboard shortcuts

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