Documentation ¶
Index ¶
Constants ¶
const ( ParamSort = "sort" ParamSortDescendingPrefix = "+" ParamSortAscendingPrefix = "-" ParamPageCursor = "page[cursor]" ParamPageNumber = "page[number]" ParamPageLimit = "page[limit]" ParamInclude = "include" )
Variables ¶
This section is empty.
Functions ¶
func EvaluateFilter ¶
func EvaluateFilter(evaluator FilterEvaluator, expr FilterExpression) error
EvaluateFilter evaluates the filter expression using the given evaluator.
Types ¶
type AndFilter ¶
type AndFilter struct { Left FilterExpression // The left operand of the AND expression. Right FilterExpression // The right operand of the AND expression. }
AndFilter defines a logical AND expression that was requested by a client.
func (*AndFilter) ApplyFilterEvaluator ¶
func (a *AndFilter) ApplyFilterEvaluator(e FilterEvaluator) error
ApplyFilterEvaluator applies the evaluator to this expression.
type Fieldset ¶
type Fieldset struct {
Property string // The name of the resource property to include in the return document.
}
Fieldset defines a sparse fieldset request made by JSON:API clients.
type Filter ¶
type Filter struct { Name string // The field name, usually referencing an attribute or relationship on a resource. Condition FilterCondition // The operator to apply on both the resource field and the token's value. Value string // The target value. }
Filter defines a filter request made by JSON:API clients. Multiple filter queries are usually combined using logical operators -- such as "and", "or", or "not" -- into a single filter expression.
func (Filter) ApplyFilterEvaluator ¶
func (c Filter) ApplyFilterEvaluator(e FilterEvaluator) error
ApplyFilterEvaluator applies the evaluator to this filter query.
type FilterCondition ¶
type FilterCondition string
FilterCondition defines the parameters of a resource property that should be included in the return document.
const ( Equal FilterCondition = "eq" // The resource property must equal the token's value. NotEqual FilterCondition = "neq" // The resource property must not equal the token's value. Contains FilterCondition = "contains" // The resource property must contain the token's value. LessThan FilterCondition = "lt" // The resource property must be less than the token's value. LessThanEqual FilterCondition = "lte" // The resource property must be less than or equal to the token's value. GreaterThan FilterCondition = "gt" // The resource property must be greater than the token's value. GreaterThanEqual FilterCondition = "gte" // The resource property must be greater than or equal to the token's value. StartsWith FilterCondition = "starts_with" // The resource property must start with the token's value. )
type FilterEvaluator ¶
type FilterEvaluator interface { // EvaluateFilter evaluates the filter expression using the given evaluator. EvaluateFilter(*Filter) error // EvaluateAndFilter evaluates the filter expression using the given evaluator. EvaluateAndFilter(*AndFilter) error // EvaluateOrFilter evaluates the filter expression using the given evaluator. EvaluateOrFilter(*OrFilter) error // EvaluateNotFilter evaluates the filter expression using the given evaluator. EvaluateNotFilter(*NotFilter) error // EvaluateIdentityFilter evaluates the filter expression using the given evaluator. EvaluateIdentityFilter() error // EvaluateCustomFilter evaluates the filter expression using the given evaluator. EvaluateCustomFilter(any) error }
FilterEvaluator defines the interface for evaluating a FilterExpression. Implementers can extend the evaluation system by defining expression types the invoke EvaluateCustomFilter() method on acceptance:
type MyEvaluator struct { // ... } func (e *MyEvaluator) EvaluateCustomFilter(value any) error { if custom, ok := value.(MyCustomExpression); ok { // ... } return nil } type MyCustomExpression struct { // ... } func (e *MyCustomExpression) ApplyFilterEvaluator(FilterEvaluator) error { return e.EvaluateCustomFilter(e) }
type FilterExpression ¶
type FilterExpression interface { fmt.Stringer // ApplyFilterEvaluator applies the evaluator to this expression. Implementors // should invoke the "EvaluateXXX" method on the evaluator that corresponds to the concrete type. ApplyFilterEvaluator(FilterEvaluator) error }
FilterExpression defines a logical expression that was requested by a client. It can be evaluated by a FilterEvaluator.
type IdentityFilter ¶
type IdentityFilter struct{}
IdentityFilter defines an identity filter expression. It always resolves to TRUE.
func (IdentityFilter) ApplyFilterEvaluator ¶
func (i IdentityFilter) ApplyFilterEvaluator(e FilterEvaluator) error
ApplyFilterEvaluator applies the evaluator to this expression.
func (IdentityFilter) String ¶
func (IdentityFilter) String() string
String returns a string representation of the identity expression.
type NotFilter ¶
type NotFilter struct {
Value FilterExpression
}
NotFilter defines a logical NOT expression that was requested by a client.
func (*NotFilter) ApplyFilterEvaluator ¶
func (n *NotFilter) ApplyFilterEvaluator(e FilterEvaluator) error
ApplyFilterEvaluator applies the evaluator to this expression.
type OrFilter ¶
type OrFilter struct { Left FilterExpression // The left operand of the OR expression. Right FilterExpression // The right operation of the OR expression. }
OrFilter defines a logical OR expression that was requested by a client.
func (*OrFilter) ApplyFilterEvaluator ¶
func (o *OrFilter) ApplyFilterEvaluator(e FilterEvaluator) error
ApplyFilterEvaluator applies the evaluator to this expression.