filter

package
v0.21.0 Latest Latest
Warning

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

Go to latest
Published: Oct 7, 2024 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrInvalidFilterFormat     = errors.New("invalid filter format")
	ErrUnknownFieldName        = errors.New("unknown field name")
	ErrUnsupportedOperatorType = errors.New("unknown operator name")
	ErrInvalidValueFormat      = errors.New("unknown field value format")
)
View Source
var (
	ErrMustBePointer                = errors.New("fields value must be a pointer")
	ErrFieldNotFound                = errors.New("field was not found")
	ErrFieldInvalidValueType        = errors.New("field value contains invalid type")
	ErrFieldUnsupportedOperatorType = errors.New("field value does not support provided operator")
)

Functions

func IsQueryField

func IsQueryField(field string) bool

Types

type FieldValue

type FieldValue struct {
	// contains filtered or unexported fields
}

func NewFieldValue

func NewFieldValue(field string) FieldValue

func (FieldValue) Evaluate

func (fv FieldValue) Evaluate(fields any) (interface{}, error)

Evaluate obtains the actual value from the provided fieldset The obtained value is then used for comparison, such as numplayers!=maxplayers

type Filter

type Filter struct {
	// contains filtered or unexported fields
}

func MustNew added in v0.7.0

func MustNew(field, rawOp string, value interface{}) Filter

func New added in v0.7.0

func New(field, rawOp string, value interface{}) (Filter, error)

func Parse added in v0.7.0

func Parse(filter string) (Filter, error)

Parse accepts a string in the form of "<field><op><value>" that represents a single filter value for the specified server field. Examples: numplayers!=maxplayers, password=0, gamevariant='SWAT 4' Returns an instance of Filter

func (Filter) Match

func (f Filter) Match(fields any) (bool, error)

Match checks whether this filter instance matches either of the provided field set

func (Filter) String

func (f Filter) String() string

type Operator

type Operator int
const (
	EQ Operator = iota
	NE
	LT
	GT
)

Jump to

Keyboard shortcuts

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