Help us shape the future of Go! Take the 2026 Go Developer Survey

filter

package
v0.17.0 Latest Latest
Warning

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

Go to latest
Published: Oct 19, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package filter provides SCIM filter expression parsing and evaluation.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FilterResources

func FilterResources[T any](resources []T, filterExpr string) ([]T, error)

FilterResources filters a slice of resources using a filter expression.

Types

type AttributePath

type AttributePath struct {
	URIPrefix     string // Optional schema URI prefix
	AttributeName string // Main attribute name
	SubAttribute  string // Optional sub-attribute
	ValueFilter   Node   // Optional value filter for multi-valued attributes
}

AttributePath represents a parsed attribute path.

func ParseAttributePath

func ParseAttributePath(path string) (*AttributePath, error)

ParseAttributePath parses an attribute path string.

func (*AttributePath) FullPath

func (ap *AttributePath) FullPath() string

FullPath returns the full attribute path including sub-attribute.

func (*AttributePath) String

func (ap *AttributePath) String() string

String returns the string representation of the attribute path.

type ComparisonNode

type ComparisonNode struct {
	AttributePath string
	Operator      Operator
	Value         any
}

ComparisonNode represents a comparison expression (e.g., "userName eq 'john'").

func (*ComparisonNode) String

func (n *ComparisonNode) String() string

String returns the string representation of the node.

func (*ComparisonNode) Type

func (n *ComparisonNode) Type() NodeType

Type returns the node type.

type Evaluator

type Evaluator struct {
	// AttributeResolver resolves attribute values from a resource.
	AttributeResolver func(resource any, attrPath string) (any, bool)
}

Evaluator evaluates filter expressions against SCIM resources.

func DefaultEvaluator

func DefaultEvaluator() *Evaluator

DefaultEvaluator returns an evaluator with a reflection-based attribute resolver.

func (*Evaluator) Evaluate

func (e *Evaluator) Evaluate(node Node, resource any) bool

Evaluate evaluates a filter expression against a resource.

type Lexer

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

Lexer tokenizes a SCIM filter expression.

func NewLexer

func NewLexer(input string) *Lexer

NewLexer creates a new lexer for the given input.

func (*Lexer) NextToken

func (l *Lexer) NextToken() Token

NextToken returns the next token from the input.

type LogicalAndNode

type LogicalAndNode struct {
	Left  Node
	Right Node
}

LogicalAndNode represents a logical AND expression.

func (*LogicalAndNode) String

func (n *LogicalAndNode) String() string

String returns the string representation of the node.

func (*LogicalAndNode) Type

func (n *LogicalAndNode) Type() NodeType

Type returns the node type.

type LogicalNotNode

type LogicalNotNode struct {
	Operand Node
}

LogicalNotNode represents a logical NOT expression.

func (*LogicalNotNode) String

func (n *LogicalNotNode) String() string

String returns the string representation of the node.

func (*LogicalNotNode) Type

func (n *LogicalNotNode) Type() NodeType

Type returns the node type.

type LogicalOrNode

type LogicalOrNode struct {
	Left  Node
	Right Node
}

LogicalOrNode represents a logical OR expression.

func (*LogicalOrNode) String

func (n *LogicalOrNode) String() string

String returns the string representation of the node.

func (*LogicalOrNode) Type

func (n *LogicalOrNode) Type() NodeType

Type returns the node type.

type Node

type Node interface {
	Type() NodeType
	String() string
}

Node represents a node in the filter AST.

func ParseFilter

func ParseFilter(filter string) (Node, error)

ParseFilter parses a SCIM filter string and returns the AST.

type NodeType

type NodeType int

NodeType represents the type of a filter AST node.

const (
	NodeComparison NodeType = iota
	NodeLogicalAnd
	NodeLogicalOr
	NodeLogicalNot
	NodeValuePath
)

type Operator

type Operator string

Operator represents a SCIM filter operator.

const (
	OpEqual              Operator = "eq"
	OpNotEqual           Operator = "ne"
	OpContains           Operator = "co"
	OpStartsWith         Operator = "sw"
	OpEndsWith           Operator = "ew"
	OpPresent            Operator = "pr"
	OpGreaterThan        Operator = "gt"
	OpGreaterThanOrEqual Operator = "ge"
	OpLessThan           Operator = "lt"
	OpLessThanOrEqual    Operator = "le"
)

Filter operators as defined in RFC 7644 Section 3.4.2.2.

const (
	OpAnd Operator = "and"
	OpOr  Operator = "or"
	OpNot Operator = "not"
)

Logical operators.

type Parser

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

Parser parses SCIM filter expressions into an AST.

func NewParser

func NewParser(input string) *Parser

NewParser creates a new parser for the given input.

func (*Parser) Parse

func (p *Parser) Parse() (Node, error)

Parse parses the filter expression and returns the AST.

type Token

type Token struct {
	Type    TokenType
	Value   string
	Literal any // The parsed literal value for strings, numbers, booleans
}

Token represents a lexical token.

func (Token) String

func (t Token) String() string

String returns a string representation of the token.

type TokenType

type TokenType int

TokenType represents the type of a lexical token.

const (
	TokenEOF TokenType = iota
	TokenIdentifier
	TokenString
	TokenNumber
	TokenBoolean
	TokenNull
	TokenOperator
	TokenAnd
	TokenOr
	TokenNot
	TokenLeftParen
	TokenRightParen
	TokenLeftBracket
	TokenRightBracket
)

type ValuePathNode

type ValuePathNode struct {
	AttributePath string
	Filter        Node
}

ValuePathNode represents a value path filter (e.g., "emails[type eq 'work']").

func (*ValuePathNode) String

func (n *ValuePathNode) String() string

String returns the string representation of the node.

func (*ValuePathNode) Type

func (n *ValuePathNode) Type() NodeType

Type returns the node type.

Jump to

Keyboard shortcuts

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