package builtins
import "github.com/open-policy-agent/opa/topdown/builtins"
Package builtins contains utilities for implementing built-in functions.
Deprecated: This package is intended for older projects transitioning from OPA v0.x and will remain for the lifetime of OPA v1.x, but its use is not recommended. For newer features and behaviours, such as defaulting to the Rego v1 syntax, use the corresponding components in the github.com/open-policy-agent/opa/v1 package instead. See https://www.openpolicyagent.org/docs/latest/v0-compatibility/ for more information.
Index ¶
- func ArrayOperand(x ast.Value, pos int) (*ast.Array, error)
- func BigIntOperand(x ast.Value, pos int) (*big.Int, error)
- func FloatToNumber(f *big.Float) ast.Number
- func IntOperand(x ast.Value, pos int) (int, error)
- func IntToNumber(i *big.Int) ast.Number
- func NewOperandElementErr(pos int, composite ast.Value, got ast.Value, expected ...string) error
- func NewOperandEnumErr(pos int, expected ...string) error
- func NewOperandErr(pos int, f string, a ...interface{}) error
- func NewOperandTypeErr(pos int, got ast.Value, expected ...string) error
- func NumberOperand(x ast.Value, pos int) (ast.Number, error)
- func NumberToFloat(n ast.Number) *big.Float
- func NumberToInt(n ast.Number) (*big.Int, error)
- func ObjectOperand(x ast.Value, pos int) (ast.Object, error)
- func RuneSliceOperand(x ast.Value, pos int) ([]rune, error)
- func SetOperand(x ast.Value, pos int) (ast.Set, error)
- func StringOperand(x ast.Value, pos int) (ast.String, error)
- func StringSliceOperand(a ast.Value, pos int) ([]string, error)
- type Cache
- type ErrOperand
- type NDBCache
Functions ¶
func ArrayOperand ¶
ArrayOperand converts x to an array. If the cast fails, a descriptive error is returned.
func BigIntOperand ¶
BigIntOperand converts x to a big int. If the cast fails, a descriptive error is returned.
func FloatToNumber ¶
FloatToNumber converts f to a number.
func IntOperand ¶
IntOperand converts x to an int. If the cast fails, a descriptive error is returned.
func IntToNumber ¶
IntToNumber converts i to a number.
func NewOperandElementErr ¶
NewOperandElementErr returns an operand error indicating an element in the composite operand was wrong.
func NewOperandEnumErr ¶
NewOperandEnumErr returns an operand error indicating a value was wrong.
func NewOperandErr ¶
NewOperandErr returns a generic operand error.
func NewOperandTypeErr ¶
NewOperandTypeErr returns an operand error indicating the operand's type was wrong.
func NumberOperand ¶
NumberOperand converts x to a number. If the cast fails, a descriptive error is returned.
func NumberToFloat ¶
NumberToFloat converts n to a big float.
func NumberToInt ¶
NumberToInt converts n to a big int. If n cannot be converted to an big int, an error is returned.
func ObjectOperand ¶
ObjectOperand converts x to an object. If the cast fails, a descriptive error is returned.
func RuneSliceOperand ¶
RuneSliceOperand converts x to a []rune. If the cast fails, a descriptive error is returned.
func SetOperand ¶
SetOperand converts x to a set. If the cast fails, a descriptive error is returned.
func StringOperand ¶
StringOperand converts x to a string. If the cast fails, a descriptive error is returned.
func StringSliceOperand ¶
StringSliceOperand converts x to a []string. If the cast fails, a descriptive error is returned.
Types ¶
type Cache ¶
Cache defines the built-in cache used by the top-down evaluation. The keys must be comparable and should not be of type string.
type ErrOperand ¶
type ErrOperand = v1.ErrOperand
ErrOperand represents an invalid operand has been passed to a built-in function. Built-ins should return ErrOperand to indicate a type error has occurred.
type NDBCache ¶
We use an ast.Object for the cached keys/values because a naive map[ast.Value]ast.Value will not correctly detect value equality of the member keys.
Source Files ¶
- Version
- v1.4.2 (latest)
- Published
- May 2, 2025
- Platform
- linux/amd64
- Imports
- 3 packages
- Last checked
- 3 weeks ago –
Tools for package owners.