gate

package
v0.0.0-...-57ebe6e Latest Latest
Warning

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

Go to latest
Published: Jul 20, 2026 License: AGPL-3.0 Imports: 11 Imported by: 0

Documentation

Overview

Package gate compiles and evaluates a route's whenExpr — the single CEL boolean that decides whether chaski acts on a request. CEL is a safe, bounded, non-Turing-complete language (no I/O, no unbounded loops), so an operator-supplied predicate over an untrusted payload can't hang or escape. Each expression is compiled and type-checked once at load (fail-fast) and evaluated under a cost limit and the request's context deadline.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Gate

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

Gate is a compiled whenExpr. The zero gate (from an empty expression) always fires, so a route without a whenExpr acts on every request (default true).

func Compile

func Compile(expr string) (*Gate, error)

Compile parses and type-checks expr. An empty expression yields an always-true gate. A syntactically invalid expression, an unknown variable/function, or one that cannot produce a boolean is an error.

func (*Gate) Eval

func (g *Gate) Eval(ctx context.Context, in Input) (bool, error)

Eval reports whether the gate fires for in. It honours ctx's deadline and returns an error on a runtime fault or a non-boolean result (the caller maps that to an operator-fault 500).

func (*Gate) Source

func (g *Gate) Source() string

Source returns the original expression text (for logs and diagnostics).

type Input

type Input struct {
	Payload any               // decoded body; dyn (map, list, or scalar)
	Headers map[string]string // lower-cased header names
	Query   map[string]string // first value per query key
	Method  string
	Route   string
	Now     time.Time
}

Input is the variable environment a whenExpr is evaluated against.

Jump to

Keyboard shortcuts

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