filter

package
v0.13.16 Latest Latest
Warning

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

Go to latest
Published: Jun 18, 2024 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package filter provides a parser and evaluator for the subscription filter syntax. See https://cloud.google.com/pubsub/docs/filtering for details on this syntax. The syntax supported is that as was documented as of 2021-03-19.

Index

Constants

This section is empty.

Variables

View Source
var DefaultParserOptions = []participle.Option{
	participle.UseLookahead(50),

	participle.Unquote("String"),
}
View Source
var Parser = participle.MustBuild[Filter](
	DefaultParserOptions...,
)

Functions

This section is empty.

Types

type AsFilter

type AsFilter interface {
	AsFilter(Writer) error
}

type AttributeOperator

type AttributeOperator string
const (
	OpEqual    AttributeOperator = "="
	OpNotEqual AttributeOperator = "!="
)

type AttributePredicate

type AttributePredicate string
const (
	PredicateHasPrefix AttributePredicate = "hasPrefix"
)

type BasicExpression

type BasicExpression struct {
	Has       *HasAttribute          `parser:"@@" json:",omitempty"`
	Value     *HasAttributeValue     `parser:"| @@" json:",omitempty"`
	Predicate *HasAttributePredicate `parser:"| @@" json:",omitempty"`
}

func (*BasicExpression) AsFilter

func (e *BasicExpression) AsFilter(w Writer) error

func (*BasicExpression) Evaluate

func (e *BasicExpression) Evaluate(attrs map[string]string) (bool, error)

func (*BasicExpression) Nil

func (e *BasicExpression) Nil() bool

type BooleanOperator

type BooleanOperator string
const (
	OpAND BooleanOperator = "AND"
	OpOR  BooleanOperator = "OR"
)

type Condition

type Condition struct {
	Term *Term   `parser:"@@" json:",omitempty"`
	And  []*Term `parser:"( (\"AND\" @@ )+" json:",omitempty"`
	Or   []*Term `parser:"| (\"OR\" @@)+ )?" json:",omitempty"`
}

func (*Condition) AsFilter

func (e *Condition) AsFilter(w Writer) (err error)

func (*Condition) Evaluate

func (e *Condition) Evaluate(attrs map[string]string) (result bool, err error)

func (*Condition) Nil

func (e *Condition) Nil() bool

type Evaluator

type Evaluator interface {
	Evaluate(attrs map[string]string) (bool, error)
}

type Filter

type Filter = Condition

type HasAttribute

type HasAttribute struct {
	Name string `parser:"\"attributes\" \":\" @(Ident|String)"`
}

func (*HasAttribute) AsFilter

func (e *HasAttribute) AsFilter(w Writer) error

func (*HasAttribute) Evaluate

func (e *HasAttribute) Evaluate(attrs map[string]string) (bool, error)

func (*HasAttribute) Nil

func (e *HasAttribute) Nil() bool

type HasAttributePredicate

type HasAttributePredicate struct {
	Predicate AttributePredicate `parser:"@(\"hasPrefix\")\"(\""`
	Name      string             `parser:"\"attributes\" \".\" @(Ident|String) \",\""`
	Value     string             `parser:"@String \")\""`
}

func (*HasAttributePredicate) AsFilter

func (e *HasAttributePredicate) AsFilter(w Writer) error

func (*HasAttributePredicate) Evaluate

func (e *HasAttributePredicate) Evaluate(attrs map[string]string) (bool, error)

func (*HasAttributePredicate) Nil

func (e *HasAttributePredicate) Nil() bool

type HasAttributeValue

type HasAttributeValue struct {
	Name  string            `parser:"\"attributes\" \".\" @(Ident|String)"`
	Op    AttributeOperator `parser:"@(\"=\" | \"!\" \"=\")"`
	Value string            `parser:"@String"`
}

func (*HasAttributeValue) AsFilter

func (e *HasAttributeValue) AsFilter(w Writer) error

func (*HasAttributeValue) Evaluate

func (e *HasAttributeValue) Evaluate(attrs map[string]string) (bool, error)

func (*HasAttributeValue) Nil

func (e *HasAttributeValue) Nil() bool

type NillableEvaluator

type NillableEvaluator interface {
	Evaluator
	Nil() bool
}

type Term

type Term struct {
	Not   bool             `parser:"@(\"NOT\"|\"-\")?"`
	Basic *BasicExpression `parser:"( @@" json:",omitempty"`
	Sub   *Condition       `parser:"| \"(\" @@ \")\" )" json:",omitempty"`
}

func (*Term) AsFilter

func (e *Term) AsFilter(w Writer) error

func (*Term) Evaluate

func (e *Term) Evaluate(attrs map[string]string) (result bool, err error)

func (*Term) Nil

func (e *Term) Nil() bool

type Writer

type Writer interface {
	WriteString(string) (int, error)
	WriteRune(rune) (int, error)
}

Writer is a subset of strings.Builder

Jump to

Keyboard shortcuts

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