opa: github.com/open-policy-agent/opa/types Index | Files

package types

import "github.com/open-policy-agent/opa/types"

Package types declares data types for Rego values and helper functions to operate on these types.

Index

Package Files

types.go

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.

func Compare Uses

func Compare(a, b Type) int

Compare returns -1, 0, 1 based on comparison between a and b.

func Contains Uses

func Contains(a, b Type) bool

Contains returns true if a is a superset or equal to b.

func Nil Uses

func Nil(a Type) bool

Nil returns true if a's type is unknown.

func Sprint Uses

func Sprint(x Type) string

Sprint returns the string representation of the type.

type Any Uses

type Any []Type

Any represents a dynamic type.

func NewAny Uses

func NewAny(of ...Type) Any

NewAny returns a new Any type.

func (Any) Contains Uses

func (t Any) Contains(other Type) bool

Contains returns true if t is a superset of other.

func (Any) MarshalJSON Uses

func (t Any) MarshalJSON() ([]byte, error)

MarshalJSON returns the JSON encoding of t.

func (Any) Merge Uses

func (t Any) Merge(other Type) Any

Merge return a new Any type that is the superset of t and other.

func (Any) String Uses

func (t Any) String() string

func (Any) Union Uses

func (t Any) Union(other Any) Any

Union returns a new Any type that is the union of the two Any types.

type Array Uses

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

Array represents the array type.

func NewArray Uses

func NewArray(static []Type, dynamic Type) *Array

NewArray returns a new Array type.

func (*Array) Dynamic Uses

func (t *Array) Dynamic() Type

Dynamic returns the type of the array's dynamic elements.

func (*Array) Len Uses

func (t *Array) Len() int

Len returns the number of static array elements.

func (*Array) MarshalJSON Uses

func (t *Array) MarshalJSON() ([]byte, error)

MarshalJSON returns the JSON encoding of t.

func (*Array) Select Uses

func (t *Array) Select(pos int) Type

Select returns the type of element at the zero-based pos.

func (*Array) String Uses

func (t *Array) String() string

type Boolean Uses

type Boolean struct{}

Boolean represents the boolean type.

func NewBoolean Uses

func NewBoolean() Boolean

NewBoolean returns a new Boolean type.

func (Boolean) MarshalJSON Uses

func (t Boolean) MarshalJSON() ([]byte, error)

MarshalJSON returns the JSON encoding of t.

func (Boolean) String Uses

func (t Boolean) String() string

type DynamicProperty Uses

type DynamicProperty struct {
    Key   Type
    Value Type
}

DynamicProperty represents a dynamic object property.

func NewDynamicProperty Uses

func NewDynamicProperty(key, value Type) *DynamicProperty

NewDynamicProperty returns a new DynamicProperty object.

func (*DynamicProperty) MarshalJSON Uses

func (p *DynamicProperty) MarshalJSON() ([]byte, error)

MarshalJSON returns the JSON encoding of p.

func (*DynamicProperty) String Uses

func (p *DynamicProperty) String() string

type Function Uses

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

Function represents a function type.

func NewFunction Uses

func NewFunction(args []Type, result Type) *Function

NewFunction returns a new Function object where xs[:len(xs)-1] are arguments and xs[len(xs)-1] is the result type.

func (*Function) Args Uses

func (t *Function) Args() []Type

Args returns the function's argument types.

func (*Function) MarshalJSON Uses

func (t *Function) MarshalJSON() ([]byte, error)

MarshalJSON returns the JSON encoding of t.

func (*Function) Result Uses

func (t *Function) Result() Type

Result returns the function's result type.

func (*Function) String Uses

func (t *Function) String() string

func (*Function) Union Uses

func (t *Function) Union(other *Function) *Function

Union returns a new function represnting the union of t and other. Functions must have the same arity to be unioned.

type Null Uses

type Null struct{}

Null represents the null type.

func NewNull Uses

func NewNull() Null

NewNull returns a new Null type.

func (Null) MarshalJSON Uses

func (t Null) MarshalJSON() ([]byte, error)

MarshalJSON returns the JSON encoding of t.

func (Null) String Uses

func (t Null) String() string

type Number Uses

type Number struct{}

Number represents the number type.

func NewNumber Uses

func NewNumber() Number

NewNumber returns a new Number type.

func (Number) MarshalJSON Uses

func (t Number) MarshalJSON() ([]byte, error)

MarshalJSON returns the JSON encoding of t.

func (Number) String Uses

func (Number) String() string

type Object Uses

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

Object represents the object type.

func NewObject Uses

func NewObject(static []*StaticProperty, dynamic *DynamicProperty) *Object

NewObject returns a new Object type.

func (*Object) DynamicValue Uses

func (t *Object) DynamicValue() Type

DynamicValue returns the type of the object's dynamic elements.

func (*Object) Keys Uses

func (t *Object) Keys() []interface{}

Keys returns the keys of the object's static elements.

func (*Object) MarshalJSON Uses

func (t *Object) MarshalJSON() ([]byte, error)

MarshalJSON returns the JSON encoding of t.

func (*Object) Select Uses

func (t *Object) Select(name interface{}) Type

Select returns the type of the named property.

func (*Object) String Uses

func (t *Object) String() string

type Set Uses

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

Set represents the set type.

func NewSet Uses

func NewSet(of Type) *Set

NewSet returns a new Set type.

func (*Set) MarshalJSON Uses

func (t *Set) MarshalJSON() ([]byte, error)

MarshalJSON returns the JSON encoding of t.

func (*Set) String Uses

func (t *Set) String() string

type StaticProperty Uses

type StaticProperty struct {
    Key   interface{}
    Value Type
}

StaticProperty represents a static object property.

func NewStaticProperty Uses

func NewStaticProperty(key interface{}, value Type) *StaticProperty

NewStaticProperty returns a new StaticProperty object.

func (*StaticProperty) MarshalJSON Uses

func (p *StaticProperty) MarshalJSON() ([]byte, error)

MarshalJSON returns the JSON encoding of p.

type String Uses

type String struct{}

String represents the string type.

func NewString Uses

func NewString() String

NewString returns a new String type.

func (String) MarshalJSON Uses

func (t String) MarshalJSON() ([]byte, error)

MarshalJSON returns the JSON encoding of t.

func (String) String Uses

func (t String) String() string

type Type Uses

type Type interface {
    String() string

    json.Marshaler
    // contains filtered or unexported methods
}

Type represents a type of a term in the language.

func Args Uses

func Args(x ...Type) []Type

Args returns an argument list.

func Keys Uses

func Keys(a Type) Type

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 Uses

func Or(a, b Type) Type

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 Uses

func Select(a Type, x interface{}) Type

Select returns a property or item of a.

func TypeOf Uses

func TypeOf(x interface{}) Type

TypeOf returns the type of the Golang native value.

func Values Uses

func Values(a Type) Type

Values returns the type of values that can be enumerated for a.

Package types imports 5 packages (graph) and is imported by 11 packages. Updated 2019-11-11. Refresh now. Tools for package owners.