Documentation
¶
Index ¶
- func DecodeJSON(b []byte, lim Limits) (any, error)
- func Equal(a, b any) bool
- func Eval(n Node, env *Env) (any, error)
- func Evaluate(src string, env *Env) (any, error)
- func ToNumber(v any) float64
- func ToString(v any) string
- func Truthy(v any) bool
- type Env
- type Error
- type HashFiler
- type Limits
- type Node
- type StaticStatus
- type Status
- type Template
- func (t *Template) Eval(env *Env) (any, error)
- func (t *Template) EvalCondition(env *Env) (bool, error)
- func (t *Template) EvalString(env *Env) (string, error)
- func (t *Template) HasExpr() bool
- func (t *Template) HasStatusCheck() bool
- func (t *Template) Literal() (string, bool)
- func (t *Template) Reads(context string) bool
- func (t *Template) Single() bool
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DecodeJSON ¶
DecodeJSON decodes untrusted JSON under the size, depth and node bounds of lim. Its errors never contain the input.
func Equal ¶
Equal implements ==: same-kind operands compare natively (strings case-insensitively), others as numbers; NaN is never equal; arrays and objects are never equal (reference equality cannot hold across contexts).
func ToNumber ¶
ToNumber coerces to a number: null 0, true 1, false 0, "" 0, a numeric string its value, anything else NaN.
Types ¶
type Env ¶
type Env struct {
Contexts map[string]any
Status Status // nil: success() is true, failure() and cancelled() false
Files HashFiler // nil: hashFiles is an error
Limits Limits
// Tenant names who is evaluating (a comparable value: an account, a
// repository). The limits on abandoned hashFiles calls are counted per
// Tenant, so one tenant's stalled filer cannot refuse another's calls.
Tenant any
// Work, when set, receives the work each evaluation spent (also one that
// was refused), ADDED to it. With Limits.MaxWork set to what is left, a
// caller makes one budget out of many evaluations.
Work *int
}
Env is what an evaluation reads. Contexts maps a context name (matched case-insensitively) to its value.
type Error ¶
Error is a syntax, limit or evaluation error. Its text names positions, kinds and source tokens, never an evaluated value, so a secret that flowed through an expression cannot appear in it.
type HashFiler ¶
HashFiler computes hashFiles(patterns...). The library has no file system; the caller supplies one (or none, and the call is an error).
HashFiles MUST honour ctx: it is cancelled when the evaluation's time is spent, and a call that ignores it keeps running after the evaluation has given up on it (it is then "abandoned" until it returns).
The limits are counted per Env.Tenant (Envs with no Tenant share one): once a tenant has maxAbandoned (16) abandoned calls, its next hashFiles is refused as saturated until some return; a tenant never has more than maxTenantInflight (64) calls in flight, so never more than 64 abandoned (calls admitted before any of them timed out can all be abandoned). Another tenant is not affected by either cap, but a hard backstop of maxInflight (256) calls in flight process-wide, over all tenants, bounds goroutines and memory, and is shared: 4 tenants with 64 calls each exhaust it for every other one. A Tenant that does not equal itself (NaN) or is uncomparable is the shared tenant. A slot is reserved before the call starts and released when it returns.
type Limits ¶
type Limits struct {
MaxLength int // bytes of one expression (default 21000, GitHub's own)
MaxDepth int // AST depth, also bounds evaluation recursion (default 100)
MaxResult int // bytes of any string an evaluation builds (default 1 MiB)
MaxJSONBytes int // input of fromJSON (default 64 KiB)
MaxJSONDepth int // nesting inside fromJSON (default 32)
MaxJSONNodes int // values inside fromJSON (default 10000)
MaxTemplate int // bytes of a ${{ }} template string (default 256 KiB)
MaxTemplateEx int // expressions in one template string (default 256)
MaxWork int // cumulative work of one evaluation, one unit per byte touched or node visited (default 16 MiB)
// MaxTime is the wall-clock deadline of one evaluation (default 2 s), read
// at the charge points: a second line of defence behind MaxWork.
MaxTime time.Duration
}
Limits bounds every resource an expression can consume. A zero field takes its default; there is no "unlimited".
type Node ¶
type Node interface {
// contains filtered or unexported methods
}
Node is a parsed expression.
type StaticStatus ¶
type StaticStatus struct{ Succeeded, Failed, Canceled bool }
StaticStatus is a Status with fixed answers.
func (StaticStatus) Cancelled ¶
func (s StaticStatus) Cancelled() bool
func (StaticStatus) Failure ¶
func (s StaticStatus) Failure() bool
func (StaticStatus) Success ¶
func (s StaticStatus) Success() bool
type Template ¶
type Template struct {
// contains filtered or unexported fields
}
Template is a string with embedded ${{ }} expressions.
func ParseCondition ¶
ParseCondition parses an `if:` value: either a template, or (as GitHub allows) a bare expression. An empty condition is the constant true.
func ParseTemplate ¶
ParseTemplate splits s into literal text and parsed expressions. A "}}" inside a single-quoted string does not close an expression.
func (*Template) Eval ¶
Eval evaluates the template: the typed value for a single expression, the concatenation (each value coerced to a string) otherwise.
func (*Template) EvalCondition ¶
EvalCondition evaluates a condition to a boolean. When it calls no status function it is implicitly wrapped in success() &&, as GitHub does.
func (*Template) EvalString ¶
EvalString is Eval coerced to a string.
func (*Template) HasStatusCheck ¶
HasStatusCheck reports whether a parsed condition calls success(), failure(), always() or cancelled(); without one GitHub wraps the condition in success() &&.
func (*Template) Literal ¶ added in v0.1.1
Literal returns the text of a template that holds no expression, which is what Eval returns for it, without the cost of an evaluation.