endpoints

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Oct 19, 2025 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.

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"`
}

ListMeta captures pagination metadata for responses.

type ListQuery

type ListQuery struct {
	Limit   int
	Offset  int
	Search  string
	Filters Filters
	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
}

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.

Jump to

Keyboard shortcuts

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