rulesengine

package
v0.9.0 Latest Latest
Warning

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

Go to latest
Published: Apr 24, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Engine

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

Engine evaluates HTTP requests against a set of rules.

func NewRuleEngine

func NewRuleEngine(rules []Rule, logger *slog.Logger) Engine

NewRuleEngine creates a new rule engine

func (*Engine) Evaluate

func (re *Engine) Evaluate(method, url string) Result

Evaluate evaluates a request and returns both result and matching rule

type Result

type Result struct {
	Allowed bool
	Rule    string // The rule that matched (if any)
}

Result contains the result of rule evaluation

type Rule

type Rule struct {

	// The path patterns that can match for this rule.
	// - nil means all paths allowed
	// - Each []string represents a path pattern (list of segments)
	// - a path segment of `*` acts as a wild card.
	PathPattern [][]string

	// The labels of the host, i.e. ["google", "com"].
	// - nil means all hosts allowed
	// - A label of `*` acts as a wild card.
	// - Exact domain patterns (e.g., "github.com") match ONLY the exact domain (no subdomains)
	// - Wildcard patterns starting with "*" (e.g., "*.github.com") match ONLY subdomains (not the base domain)
	HostPattern []string

	// The allowed http methods.
	// - nil means all methods allowed
	MethodPatterns map[string]struct{}

	// Raw rule string for logging
	Raw string
}

Rule represents an allow rule passed to the cli with --allow or read from the config file. Rules have a specific grammar that we need to parse carefully. Example: --allow="method=GET,PATCH domain=wibble.wobble.com, path=/posts/*"

func ParseAllowSpecs

func ParseAllowSpecs(allowStrings []string) ([]Rule, error)

ParseAllowSpecs parses a slice of --allow specs into allow Rules.

Jump to

Keyboard shortcuts

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