collection

package
v0.0.0-...-73d3728 Latest Latest
Warning

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

Go to latest
Published: Jan 19, 2024 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ParamPage   string    = "page"
	ParamSize   string    = "size"
	ParamSort   string    = "sort"
	ParamFilter string    = "filter"
	SortAsc     Direction = "asc"
	SortDesc    Direction = "desc"
	OpEq        Operator  = "=="
	OpNe        Operator  = "!="
	OpGt        Operator  = ">"
	OpLt        Operator  = "<"
	OpGe        Operator  = ">="
	OpLe        Operator  = "<="
)

symbols

Variables

View Source
var BoolOps = StringOps
View Source
var NumberOps = []Operator{OpEq, OpNe, OpGt, OpLt, OpGe, OpLe}
View Source
var StringOps = []Operator{OpEq, OpNe}

Functions

This section is empty.

Types

type Direction

type Direction string

type FieldCapability

type FieldCapability struct {
	Filter    bool
	FilterOps []Operator
	Sort      bool
}

type FilterSpec

type FilterSpec struct {
	Field    string
	Operator Operator
	Value    any
}

type Operator

type Operator string

type Page

type Page[T any] struct {
	Results []T    `json:"results"`
	Page    uint64 `json:"page"`
	Size    uint64 `json:"size"`
}

type QueryError

type QueryError struct {
	Message string
}

QueryError is returned when a query is invalid.

func (QueryError) Error

func (qe QueryError) Error() string

type QuerySpec

type QuerySpec struct {
	Filters []FilterSpec
	Sorts   []SortSpec
	Page    uint64 // 0 is not set
	Size    uint64 // 0 is not set
}

func ParseQuery

func ParseQuery(urlQuery url.Values) (QuerySpec, error)

func (QuerySpec) Validate

func (q QuerySpec) Validate(fieldCapabilities map[string]FieldCapability) error

Validates the query against a set of field capabilities.

type SortSpec

type SortSpec struct {
	Field     string
	Direction Direction
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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