list

package
v1.0.7 Latest Latest
Warning

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

Go to latest
Published: Jan 11, 2026 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Filters

type Filters map[string][]string

Filters describes allowed filter values.

func DefaultFilterParser

func DefaultFilterParser(values url.Values, cfg ListQueryConfig) Filters

DefaultFilterParser implements the toolkit's standard query syntax.

type ListMeta

type ListMeta struct {
	Total   int                 `json:"total"`
	Count   int                 `json:"count"`
	Limit   int                 `json:"limit"`
	Offset  int                 `json:"offset"`
	Filters map[string][]string `json:"filters,omitempty"`
	Search  string              `json:"search,omitempty"`
	Sort    []SortField         `json:"sort,omitempty"`
}

ListMeta captures pagination metadata for responses.

type ListQuery

type ListQuery struct {
	Limit   int
	Offset  int
	Search  string
	Filters Filters
	Sort    []SortField
	Raw     url.Values
	// contains filtered or unexported fields
}

ListQuery captures pagination, search, and filter inputs from a request.

func ParseListQuery

func ParseListQuery(r *http.Request, cfg ListQueryConfig) ListQuery

ParseListQuery parses pagination and filters from the HTTP request according to cfg.

func (ListQuery) First

func (q ListQuery) First(key string) string

First returns the first filter value for the key if present.

func (ListQuery) Has

func (q ListQuery) Has(key string) bool

Has reports whether the filter key exists.

func (ListQuery) MissingRequired

func (q ListQuery) MissingRequired() []string

MissingRequired returns filter keys that were required but absent.

type ListQueryConfig

type ListQueryConfig struct {
	DefaultLimit   int
	MaxLimit       int
	AllowedFilters []string
	Required       []string
	SearchParam    string
	SortParam      string
	AllowedSorts   []string
	DefaultSort    []SortField
	// FilterParser overrides the default filter parser when set.
	FilterParser func(values url.Values, cfg ListQueryConfig) Filters
	// SortParser overrides the default sort parser when set.
	SortParser func(values url.Values, cfg ListQueryConfig) []SortField
}

ListQueryConfig configures parsing behaviour for list endpoints.

type ListResponse

type ListResponse[T any] struct {
	Data []T      `json:"data"`
	Meta ListMeta `json:"meta"`
}

ListResponse wraps list results with metadata.

func NewListResponse

func NewListResponse[T any](items []T, total int, query ListQuery) ListResponse[T]

NewListResponse constructs a ListResponse with paging metadata.

type SortField

type SortField struct {
	Field string `json:"field"`
	Desc  bool   `json:"desc"`
}

SortField describes a field and direction used for ordering results.

func DefaultSortParser

func DefaultSortParser(values url.Values, cfg ListQueryConfig) []SortField

DefaultSortParser implements the toolkit's comma-delimited sort syntax.

Jump to

Keyboard shortcuts

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