filter

package
v0.4.7 Latest Latest
Warning

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

Go to latest
Published: Jun 21, 2025 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrInvalidOperatorOrOperands = errors.New("invalid operator or operands")

Functions

func FormatSize

func FormatSize(size int64) string

FormatSize takes an int64 representation of a size in bytes and returns a string representation of the size with a unit (e.g. "1G", "10M"). The size is rounded to the nearest whole number if it is an integer, otherwise it is rounded to one decimal place.

func ParseSize

func ParseSize(sizeStr string) (int64, error)

ParseSize takes a string representation of a size (e.g. "1G", "10M") and returns the size in bytes as an int64. If the input string is not a valid size representation, an error is returned.

Types

type FilterExpression

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

FilterExpression is a parsed and compiled representation of a filter string. It can be used to efficiently test whether a set of variables matches the filter.

func CreateFilter

func CreateFilter(filter string) (*FilterExpression, error)

CreateFilter parses the given filter string and returns a compiled FilterExpression that can be used to efficiently test the filter. If the filter string is not valid, an error is returned.

func (*FilterExpression) Test

func (x *FilterExpression) Test(getter VariableGetter) (bool, error)

Test tests whether the set of variables provided by the getter function matches the filter expression. It returns a boolean value indicating whether the variables match the filter, as well as an error value if there was a problem evaluating the expression, like a type mismatch or a missing variable.

type Value

type Value struct {
	Number  *int64
	Text    *string
	Boolean *bool
}

Value is a type that can represent a number, a string, or a boolean value.

func BoolValue

func BoolValue(v bool) *Value

BoolValue creates a new Value instance that represents the given boolean value.

func NumberValue

func NumberValue(f int64) *Value

NumberValue creates a new Value instance that represents the given number.

func TextValue

func TextValue(s string) *Value

TextValue creates a new Value instance that represents the given string.

func (*Value) String added in v0.2.0

func (v *Value) String() string

String returns a string representation of the value. If the value is nil, an empty string is returned.

type VariableGetter

type VariableGetter func(name string) *Value

VariableGetter is a function type that is used to retrieve the value of a variable by its name. It takes a single string argument (the name of the variable) and returns a pointer to a Value instance that represents the value of the variable.

Jump to

Keyboard shortcuts

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