filters

package
v1.0.0-beta.228 Latest Latest
Warning

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

Go to latest
Published: May 19, 2026 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
const (
	OpEq        = "eq"
	OpNeq       = "neq"
	OpGt        = "gt"
	OpGte       = "gte"
	OpLt        = "lt"
	OpLte       = "lte"
	OpContains  = "contains"
	OpOeq       = "oeq"
	OpOcontains = "ocontains"
	OpExists    = "exists"
	OpNexists   = "nexists"
)

Operator constants used in filter[field][op]=value query parameters.

Variables

View Source
var (
	ErrTooManyItems        = fmt.Errorf("too many comma-separated items (max %d)", maxCommaSeparatedItems)
	ErrUnsupportedOperator = errors.New("unsupported operator")
	ErrInvalidNumber       = errors.New("invalid number")
	ErrInvalidDateTime     = errors.New("invalid datetime")
)
View Source
var (
	FilterULIDType = reflect.TypeFor[*FilterULID]()
)

Functions

func FromAPIFilterBoolean

func FromAPIFilterBoolean(f *FilterBoolean) (*filter.FilterBoolean, error)

FromAPIFilterBoolean converts an API FilterBoolean to filter.FilterBoolean.

func FromAPIFilterDateTime

func FromAPIFilterDateTime(f *FilterDateTime) (*filter.FilterTime, error)

FromAPIFilterDateTime converts an API FilterDateTime to filter.FilterTime.

func FromAPIFilterLabel

func FromAPIFilterLabel(f *FilterLabel) (*filter.FilterString, error)

FromAPIFilterLabel converts an API FilterLabel to filter.FilterString.

func FromAPIFilterLabels

func FromAPIFilterLabels(f *FilterLabels) (map[string]filter.FilterString, error)

FromAPIFilterLabels converts an API FilterLabels to map[string]filter.FilterString.

func FromAPIFilterNumeric

func FromAPIFilterNumeric(f *FilterNumeric) (*filter.FilterFloat, error)

FromAPIFilterNumeric converts an API FilterNumeric to filter.FilterFloat.

func FromAPIFilterString

func FromAPIFilterString(f *FilterString) (*filter.FilterString, error)

FromAPIFilterString converts an API FilterString to filter.FilterString.

func FromAPIFilterStringExact

func FromAPIFilterStringExact(f *FilterStringExact) (*filter.FilterString, error)

FromAPIFilterStringExact converts an API FilterStringExact to filter.FilterString.

func FromAPIFilterULID

func FromAPIFilterULID(f *FilterULID) (*filter.FilterULID, error)

FromAPIFilterULID converts an API FilterString to filter.FilterULID.

func FromAPIStatusFilter

func FromAPIStatusFilter[T validator[T]](ctx context.Context, f *FilterStringExact) ([]T, error)

func Parse

func Parse(qs url.Values, target any) error

Parse populates a filter struct from URL query values. The target must be a pointer to a struct (or pointer-to-pointer-to-struct) whose fields are filter types. Field names are resolved from json struct tags.

Types

type FilterBoolean

type FilterBoolean struct {
	// Eq requires the field to match the provided value exactly.
	Eq *bool `json:"eq,omitempty"`
}

FilterBoolean represents a filter operation on a boolean field.

type FilterDateTime

type FilterDateTime struct {
	// Eq requires the field to match the provided value exactly.
	Eq *time.Time `json:"eq,omitempty"`

	// Gt requires the field to be greater than the provided value.
	Gt *time.Time `json:"gt,omitempty"`

	// Gte requires the field to be greater than or equal to the provided value.
	Gte *time.Time `json:"gte,omitempty"`

	// Lt requires the field to be less than the provided value.
	Lt *time.Time `json:"lt,omitempty"`

	// Lte requires the field to be less than or equal to the provided value.
	Lte *time.Time `json:"lte,omitempty"`
}

FilterDateTime represents a filter operation on a datetime field.

type FilterLabel

type FilterLabel struct {
	// Eq requires the field to match the provided value exactly.
	Eq *string `json:"eq,omitempty"`

	// Contains requires the field to contain the provided value (case-insensitive).
	Contains *string `json:"contains,omitempty"`

	// Ocontains requires the field to contain any of the provided comma-separated values (case-insensitive).
	Ocontains []string `json:"ocontains,omitempty"`

	// Oeq requires the field to match any of the provided comma-separated values (case-sensitive).
	Oeq []string `json:"oeq,omitempty"`

	// Neq requires the field to not match the provided value.
	Neq *string `json:"neq,omitempty"`
}

FilterLabel represents a filter operation on a label key.

type FilterLabels

type FilterLabels = map[string]FilterLabel

FilterLabels is a map of label keys to filter operations.

type FilterNumeric

type FilterNumeric struct {
	// Eq requires the field to match the provided value exactly.
	Eq *float64 `json:"eq,omitempty"`

	// Neq requires the field to not match the provided value.
	Neq *float64 `json:"neq,omitempty"`

	// Oeq requires the field to match any of the provided comma-separated values.
	Oeq []float64 `json:"oeq,omitempty"`

	// Gt requires the field to be greater than the provided value.
	Gt *float64 `json:"gt,omitempty"`

	// Gte requires the field to be greater than or equal to the provided value.
	Gte *float64 `json:"gte,omitempty"`

	// Lt requires the field to be less than the provided value.
	Lt *float64 `json:"lt,omitempty"`

	// Lte requires the field to be less than or equal to the provided value.
	Lte *float64 `json:"lte,omitempty"`
}

FilterNumeric represents a filter operation on a numeric field.

type FilterString

type FilterString struct {
	// Eq requires the field to match the provided value exactly (case-sensitive).
	Eq *string `json:"eq,omitempty"`

	// Neq requires the field to not match the provided value (case-sensitive).
	Neq *string `json:"neq,omitempty"`

	// Gt requires the field to be greater than the provided value.
	Gt *string `json:"gt,omitempty"`

	// Gte requires the field to be greater than or equal to the provided value.
	Gte *string `json:"gte,omitempty"`

	// Lt requires the field to be less than the provided value.
	Lt *string `json:"lt,omitempty"`

	// Lte requires the field to be less than or equal to the provided value.
	Lte *string `json:"lte,omitempty"`

	// Contains requires the field to contain the provided value (case-insensitive).
	Contains *string `json:"contains,omitempty"`

	// Oeq requires the field to match any of the provided comma-separated values (case-sensitive).
	Oeq []string `json:"oeq,omitempty"`

	// Ocontains requires the field to contain any of the provided comma-separated values (case-insensitive).
	Ocontains []string `json:"ocontains,omitempty"`

	// Exists requires the field to be present (true) or absent (false).
	Exists *bool `json:"$exists,omitempty"`
}

FilterString represents a filter operation on a string field.

type FilterStringExact

type FilterStringExact struct {
	// Eq requires the field to match the provided value exactly (case-sensitive).
	Eq *string `json:"eq,omitempty"`

	// Neq requires the field to not match the provided value exactly (case-sensitive).
	Neq *string `json:"neq,omitempty"`

	// Oeq requires the field to match any of the provided comma-separated values (case-sensitive).
	Oeq []string `json:"oeq,omitempty"`
}

FilterStringExact represents a filter operation on a string field that only supports exact matching.

type FilterULID

type FilterULID struct {
	// Eq requires the field to match the provided value exactly (case-sensitive).
	Eq *string `json:"eq,omitempty"`

	// Neq requires the field to not match the provided value (case-sensitive).
	Neq *string `json:"neq,omitempty"`

	// Oeq requires the field to match any of the provided comma-separated values (case-sensitive).
	Oeq []string `json:"oeq,omitempty"`
}

FilterULID represents a filter operation on a string field that satisfies ULID format.

Jump to

Keyboard shortcuts

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