op

package
v0.6.0 Latest Latest
Warning

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

Go to latest
Published: Aug 15, 2026 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

Package op provides the built-in operators.

Every operator here reports required literals wherever it honestly can, which is what lets the prefilter skip it on benign traffic. Operators that cannot — Func, and anything genuinely input-independent — are unconditional, and the compile report says so by name. The cost of an unconditional rule is a build-time fact rather than a production surprise. See docs/RULES.md §5.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Contains

func Contains(needle string) rules.Operator

Contains matches values containing needle, case-insensitively.

The comparison is case-insensitive because the prefilter folds case, and an operator that were stricter than its own prefilter would be skipped for inputs it would have matched — a silent miss. Operators must never be narrower than the literals they declare.

func ContainsAny

func ContainsAny(needles ...string) rules.Operator

ContainsAny matches values containing any of the needles, case-insensitively.

func Equals

func Equals(want string) rules.Operator

Equals matches values equal to want, case-sensitively.

func HasPrefix

func HasPrefix(prefix string) rules.Operator

HasPrefix matches values beginning with prefix, case-insensitively.

Types

type FuncOperator

type FuncOperator = funcOp

FuncOperator is the operator Func returns.

Exported for its methods rather than for its fields: a caller builds one with Func and refines it with WithLiterals.

func Func

func Func(name string, fn func(value []byte) bool) *FuncOperator

Func wraps an arbitrary predicate.

This is the escape hatch, and it is priced accordingly. The engine cannot extract literals from a Go function, so a Func rule is unconditional: it runs on every request in its phase and its cost shows up in the compile report. Third-party predicates also run behind a recovering boundary, which built-in operators do not need.

Use WithLiterals when you can honestly assert what the predicate requires:

op.Func("graphql-introspection", isIntrospection).WithLiterals("__schema")

It returns the concrete type rather than the interface so that chains like the one above compile. Returning rules.Operator made the documented form a type error and forced callers through a LiteralHinter assertion, which is not what an escape hatch should feel like -- CLAUDE.md §2b asks for one that is always present and always visible. *FuncOperator satisfies rules.Operator, so nothing that only stores the result had to change.

type LiteralHinter

type LiteralHinter interface {
	rules.Operator
	WithLiterals(literals ...string) *FuncOperator
}

LiteralHinter is implemented by operators that accept a required-literal assertion. It lets callers attach hints without knowing the concrete type.

Directories

Path Synopsis
Package rx provides a regular-expression operator.
Package rx provides a regular-expression operator.

Jump to

Keyboard shortcuts

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