package types
import "github.com/open-policy-agent/opa/types"
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.
Package types declares data types for Rego values and helper functions to operate on these types.
Index ¶
- Variables
- func Arity(x Type) int
- func Compare(a, b Type) int
- func Contains(a, b Type) bool
- func Nil(a Type) bool
- func Sprint(x Type) string
- func Void(x Type) bool
- type Any
- type Array
- type Boolean
- type DynamicProperty
- type FuncArgs
- type Function
- func NewFunction(args []Type, result Type) *Function
- func NewVariadicFunction(args []Type, varargs Type, result Type) *Function
- type NamedType
- type Null
- type Number
- type Object
- type Set
- type StaticProperty
- type String
- type Type
Variables ¶
var A = NewAny()
A represents the superset of all types.
var B = NewBoolean()
B represents an instance of the boolean type.
var N = NewNumber()
N represents an instance of the number type.
var S = NewString()
S represents an instance of the string type.
Functions ¶
func Arity ¶
Arity returns the number of arguments in the function signature or zero if x is not a function. If the type is unknown, this function returns -1.
func Compare ¶
Compare returns -1, 0, 1 based on comparison between a and b.
func Contains ¶
Contains returns true if a is a superset or equal to b.
func Nil ¶
Nil returns true if a's type is unknown.
func Sprint ¶
Sprint returns the string representation of the type.
func Void ¶
Void returns true if the function has no return value. This function returns false if x is not a function.
Types ¶
type Any ¶
Any represents a dynamic type.
func NewAny ¶
NewAny returns a new Any type.
type Array ¶
Array represents the array type.
func NewArray ¶
NewArray returns a new Array type.
type Boolean ¶
Boolean represents the boolean type.
func NewBoolean ¶
func NewBoolean() Boolean
NewBoolean returns a new Boolean type.
type DynamicProperty ¶
type DynamicProperty = v1.DynamicProperty
DynamicProperty represents a dynamic object property.
func NewDynamicProperty ¶
func NewDynamicProperty(key, value Type) *DynamicProperty
NewDynamicProperty returns a new DynamicProperty object.
type FuncArgs ¶
FuncArgs represents the arguments that can be passed to a function.
type Function ¶
Function represents a function type.
func NewFunction ¶
NewFunction returns a new Function object of the given argument and result types.
func NewVariadicFunction ¶
NewVariadicFunction returns a new Function object. This function sets the variadic bit on the signature. Non-void variadic functions are not currently supported.
type NamedType ¶
NamedType represents a type alias with an arbitrary name and description. This is useful for generating documentation for built-in functions.
func Named ¶
Named returns the passed type as a named type. Named types are only valid at the top level of built-in functions. Note that nested named types cause panic.
type Null ¶
Null represents the null type.
func NewNull ¶
func NewNull() Null
NewNull returns a new Null type.
type Number ¶
Number represents the number type.
func NewNumber ¶
func NewNumber() Number
NewNumber returns a new Number type.
type Object ¶
Object represents the object type.
func NewObject ¶
func NewObject(static []*StaticProperty, dynamic *DynamicProperty) *Object
NewObject returns a new Object type.
type Set ¶
Set represents the set type.
func NewSet ¶
NewSet returns a new Set type.
type StaticProperty ¶
type StaticProperty = v1.StaticProperty
StaticProperty represents a static object property.
func NewStaticProperty ¶
func NewStaticProperty(key interface{}, value Type) *StaticProperty
NewStaticProperty returns a new StaticProperty object.
type String ¶
String represents the string type.
func NewString ¶
func NewString() String
NewString returns a new String type.
type Type ¶
Type represents a type of a term in the language.
func Args ¶
Args returns an argument list.
func Keys ¶
Keys returns the type of keys that can be enumerated for a. For arrays, the keys are always number types, for objects the keys are always string types, and for sets the keys are always the type of the set element.
func Or ¶
Or returns a type that represents the union of a and b. If one type is a superset of the other, the superset is returned unchanged.
func Select ¶
Select returns a property or item of a.
func TypeOf ¶
func TypeOf(x interface{}) Type
TypeOf returns the type of the Golang native value.
func Unmarshal ¶
Unmarshal deserializes bs and returns the resulting type.
func Values ¶
Values returns the type of values that can be enumerated for a.
Source Files ¶
- Version
- v1.4.2 (latest)
- Published
- May 2, 2025
- Platform
- linux/amd64
- Imports
- 1 packages
- Last checked
- 4 hours ago –
Tools for package owners.