Movatterモバイル変換


[0]ホーム

URL:


types

package
v0.26.1Latest Latest
Warning

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

Go to latest
Published: Aug 18, 2025 License:Apache-2.0, BSD-3-ClauseImports:29Imported by:449

Details

Repository

github.com/google/cel-go

Links

Documentation

Overview

Package types contains the types, traits, and utilities common to allcomponents of expression handling.

Index

Constants

View Source
const (False =Bool(false)True  =Bool(true))

Boolean constants

View Source
const (// IntZero is the zero-value for IntIntZero   =Int(0)IntOne    =Int(1)IntNegOne =Int(-1))

Int constants used for comparison results.

Variables

View Source
var (// OptionalType indicates the runtime type of an optional value.OptionalType =NewOpaqueType("optional_type")// OptionalNone is a sentinel value which is used to indicate an empty optional value.OptionalNone = &Optional{})
View Source
var (// AnyType represents the google.protobuf.Any type.AnyType = &Type{kind:AnyKind,runtimeTypeName: "google.protobuf.Any",traitMask:traits.FieldTesterType |traits.IndexerType,}// BoolType represents the bool type.BoolType = &Type{kind:BoolKind,runtimeTypeName: "bool",traitMask:traits.ComparerType |traits.NegatorType,}// BytesType represents the bytes type.BytesType = &Type{kind:BytesKind,runtimeTypeName: "bytes",traitMask:traits.AdderType |traits.ComparerType |traits.SizerType,}// DoubleType represents the double type.DoubleType = &Type{kind:DoubleKind,runtimeTypeName: "double",traitMask:traits.AdderType |traits.ComparerType |traits.DividerType |traits.MultiplierType |traits.NegatorType |traits.SubtractorType,}// DurationType represents the CEL duration type.DurationType = &Type{kind:DurationKind,runtimeTypeName: "google.protobuf.Duration",traitMask:traits.AdderType |traits.ComparerType |traits.NegatorType |traits.ReceiverType |traits.SubtractorType,}// DynType represents a dynamic CEL type whose type will be determined at runtime from context.DynType = &Type{kind:DynKind,runtimeTypeName: "dyn",}// ErrorType represents a CEL error value.ErrorType = &Type{kind:ErrorKind,runtimeTypeName: "error",}// IntType represents the int type.IntType = &Type{kind:IntKind,runtimeTypeName: "int",traitMask:traits.AdderType |traits.ComparerType |traits.DividerType |traits.ModderType |traits.MultiplierType |traits.NegatorType |traits.SubtractorType,}// ListType represents the runtime list type.ListType =NewListType(DynType)// MapType represents the runtime map type.MapType =NewMapType(DynType,DynType)// NullType represents the type of a null value.NullType = &Type{kind:NullTypeKind,runtimeTypeName: "null_type",}// StringType represents the string type.StringType = &Type{kind:StringKind,runtimeTypeName: "string",traitMask:traits.AdderType |traits.ComparerType |traits.MatcherType |traits.ReceiverType |traits.SizerType,}// TimestampType represents the time type.TimestampType = &Type{kind:TimestampKind,runtimeTypeName: "google.protobuf.Timestamp",traitMask:traits.AdderType |traits.ComparerType |traits.ReceiverType |traits.SubtractorType,}// TypeType represents a CEL typeTypeType = &Type{kind:TypeKind,runtimeTypeName: "type",}// UintType represents a uint type.UintType = &Type{kind:UintKind,runtimeTypeName: "uint",traitMask:traits.AdderType |traits.ComparerType |traits.DividerType |traits.ModderType |traits.MultiplierType |traits.SubtractorType,}// UnknownType represents an unknown value type.UnknownType = &Type{kind:UnknownKind,runtimeTypeName: "unknown",})
View Source
var (// DefaultTypeAdapter adapts canonical CEL types from their equivalent Go values.DefaultTypeAdapter = &defaultTypeAdapter{})
View Source
var (// ErrType singleton.ErrType =NewOpaqueType("error"))
View Source
var (// IteratorType singleton.IteratorType =NewObjectType("iterator",traits.IteratorType))
View Source
var (// NullValue singleton.NullValue =Null(structpb.NullValue_NULL_VALUE))

Functions

funcDurationGetHoursadded inv0.17.0

func DurationGetHours(valref.Val)ref.Val

DurationGetHours returns the duration in hours.

funcDurationGetMillisecondsadded inv0.17.0

func DurationGetMilliseconds(valref.Val)ref.Val

DurationGetMilliseconds returns duration in milliseconds.

funcDurationGetMinutesadded inv0.17.0

func DurationGetMinutes(valref.Val)ref.Val

DurationGetMinutes returns duration in minutes.

funcDurationGetSecondsadded inv0.17.0

func DurationGetSeconds(valref.Val)ref.Val

DurationGetSeconds returns duration in seconds.

funcEqualadded inv0.10.0

func Equal(lhsref.Val, rhsref.Val)ref.Val

Equal returns whether the two ref.Value are heterogeneously equivalent.

funcFormatadded inv0.25.0

func Format(valref.Val)string

Format formats the value as a string. The result is only intended for human consumption and ignores errors.Do not depend on the output being stable. It may change at any time.

funcIndexOrErroradded inv0.13.0

func IndexOrError(indexref.Val) (int,error)

IndexOrError converts an input index value into either a lossless integer index or an error.

funcInsertMapKeyValueadded inv0.22.0

func InsertMapKeyValue(mtraits.Mapper, k, vref.Val)ref.Val

InsertMapKeyValue inserts a key, value pair into the target map if the target map does notalready contain the given key.

If the map is mutable, it is modified in-place per the MutableMapper contract.If the map is not mutable, a copy containing the new key, value pair is made.

funcIsBool

func IsBool(elemref.Val)bool

IsBool returns whether the input ref.Val or ref.Type is equal to BoolType.

funcIsError

func IsError(valref.Val)bool

IsError returns whether the input element ref.Type or ref.Val is equal tothe ErrType singleton.

funcIsPrimitiveTypeadded inv0.3.0

func IsPrimitiveType(valref.Val)bool

IsPrimitiveType returns whether the input element ref.Val is a primitive type.Note, primitive types do not include well-known types such as Duration and Timestamp.

funcIsUnknown

func IsUnknown(valref.Val)bool

IsUnknown returns whether the element ref.Val is in instance of *types.Unknown

funcIsUnknownOrError

func IsUnknownOrError(valref.Val)bool

IsUnknownOrError returns whether the input element ref.Val is an ErrType or UnknownType.

funcLabelErrNodeadded inv0.19.0

func LabelErrNode(idint64, valref.Val)ref.Val

LabelErrNode returns val unaltered it is not an Err or if the error has a non-zeroAST node ID already present. Otherwise the id is added to the error forrecovery with the Err.NodeID method.

funcMaybeNoSuchOverloadErradded inv0.4.0

func MaybeNoSuchOverloadErr(valref.Val)ref.Val

MaybeNoSuchOverloadErr returns the error or unknown if the input ref.Val is one of these types,else a new no such overload error.

funcNewDynamicList

func NewDynamicList(adapterAdapter, valueany)traits.Lister

NewDynamicList returns a traits.Lister with heterogenous elements.value should be an array of "native" types, i.e. any type thatNativeToValue() can convert to a ref.Val.

funcNewDynamicMap

func NewDynamicMap(adapterAdapter, valueany)traits.Mapper

NewDynamicMap returns a traits.Mapper value with dynamic key, value pairs.

funcNewErr

func NewErr(formatstring, args ...any)ref.Val

NewErr creates a new Err described by the format string and args.TODO: Audit the use of this function and standardize the error messages and codes.

funcNewErrFromStringadded inv0.23.0

func NewErrFromString(messagestring)ref.Val

NewErrFromString creates a new Err with the provided message.TODO: Audit the use of this function and standardize the error messages and codes.

funcNewErrWithNodeIDadded inv0.19.0

func NewErrWithNodeID(idint64, formatstring, args ...any)ref.Val

NewErrWithNodeID creates a new Err described by the format string and args.TODO: Audit the use of this function and standardize the error messages and codes.

funcNewJSONList

func NewJSONList(adapterAdapter, l *structpb.ListValue)traits.Lister

NewJSONList returns a traits.Lister based on structpb.ListValue instance.

funcNewJSONStruct

func NewJSONStruct(adapterAdapter, value *structpb.Struct)traits.Mapper

NewJSONStruct creates a traits.Mapper implementation backed by a JSON struct that has beenencoded in protocol buffer form.

The `adapter` argument provides type adaptation capabilities from proto to CEL.

funcNewMutableListadded inv0.10.0

func NewMutableList(adapterAdapter)traits.MutableLister

NewMutableList creates a new mutable list whose internal state can be modified.

funcNewMutableMapadded inv0.22.0

func NewMutableMap(adapterAdapter, mutableValues map[ref.Val]ref.Val)traits.MutableMapper

NewMutableMap constructs a mutable map from an adapter and a set of map values.

funcNewObject

func NewObject(adapterAdapter,typeDesc *pb.TypeDescription,typeValueref.Val,valueproto.Message)ref.Val

NewObject returns an object based on a proto.Message value which handlesconversion between protobuf type values and expression type values.Objects support indexing and iteration.

Note: the type value is pulled from the list of registered types within thetype provider. If the proto type is not registered within the type provider,then this will result in an error within the type adapter / provider.

funcNewProtoListadded inv0.7.0

func NewProtoList(adapterAdapter, listprotoreflect.List)traits.Lister

NewProtoList returns a traits.Lister based on a pb.List instance.

funcNewProtoMapadded inv0.7.0

func NewProtoMap(adapterAdapter, value *pb.Map)traits.Mapper

NewProtoMap returns a specialized traits.Mapper for handling protobuf map values.

funcNewRefValListadded inv0.7.0

func NewRefValList(adapterAdapter, elems []ref.Val)traits.Lister

NewRefValList returns a traits.Lister with ref.Val elements.

This type specialization is used with list literals within CEL expressions.

funcNewRefValMapadded inv0.7.0

func NewRefValMap(adapterAdapter, value map[ref.Val]ref.Val)traits.Mapper

NewRefValMap returns a specialized traits.Mapper with CEL valued keys and values.

funcNewStringInterfaceMapadded inv0.7.0

func NewStringInterfaceMap(adapterAdapter, value map[string]any)traits.Mapper

NewStringInterfaceMap returns a specialized traits.Mapper with string keys and interface values.

funcNewStringList

func NewStringList(adapterAdapter, elems []string)traits.Lister

NewStringList returns a traits.Lister containing only strings.

funcNewStringStringMap

func NewStringStringMap(adapterAdapter, value map[string]string)traits.Mapper

NewStringStringMap returns a specialized traits.Mapper with string keys and values.

funcNoSuchOverloadErradded inv0.4.0

func NoSuchOverloadErr()ref.Val

NoSuchOverloadErr returns a new types.Err instance with a no such overload message.

funcStringContainsadded inv0.17.0

func StringContains(s, subref.Val)ref.Val

StringContains returns whether the string contains a substring.

funcStringEndsWithadded inv0.17.0

func StringEndsWith(s, sufref.Val)ref.Val

StringEndsWith returns whether the target string contains the input suffix.

funcStringStartsWithadded inv0.17.0

func StringStartsWith(s, preref.Val)ref.Val

StringStartsWith returns whether the target string contains the input prefix.

funcToFoldableListadded inv0.22.0

func ToFoldableList(ltraits.Lister)traits.Foldable

ToFoldableList will create a Foldable version of a list suitable for key-value pair iteration.

For values which are already Foldable, this call is a no-op. For all other values, the fold isdriven via the Size() and Get() calls which means that the folding will function, but take aperformance hit.

funcToFoldableMapadded inv0.22.0

func ToFoldableMap(mtraits.Mapper)traits.Foldable

ToFoldableMap will create a Foldable version of a map suitable for key-value pair iteration.

For values which are already Foldable, this call is a no-op. For all other values, the foldis driven via the Iterator HasNext() and Next() calls as well as the map's Get() methodwhich means that the folding will function, but take a performance hit.

funcTypeToExprTypeadded inv0.17.0

func TypeToExprType(t *Type) (*exprpb.Type,error)

TypeToExprType converts a CEL-native type representation to a protobuf CEL Type representation.

funcTypeToProtoadded inv0.23.0

func TypeToProto(t *Type) (*celpb.Type,error)

TypeToProto converts from a CEL-native type representation to canonical CEL celpb.Type protobuf type.

funcUnsupportedRefValConversionErradded inv0.7.0

func UnsupportedRefValConversionErr(valany)ref.Val

UnsupportedRefValConversionErr returns a types.NewErr instance with a no such conversionmessage that indicates that the native value could not be converted to a CEL ref.Val.

funcValOrErr

func ValOrErr(valref.Val, formatstring, args ...any)ref.Val

ValOrErr either returns the existing error or creates a new one.TODO: Audit the use of this function and standardize the error messages and codes.

funcWrapErradded inv0.14.0

func WrapErr(errerror)ref.Val

WrapErr wraps an existing Go error value into a CEL Err value.

Types

typeAdapteradded inv0.17.0

type Adapter =ref.TypeAdapter

Adapter converts native Go values of varying type and complexity to equivalent CEL values.

typeAttributeQualifieradded inv0.17.0

type AttributeQualifier interface {bool |int64 |uint64 |string}

AttributeQualifier constrains the possible types which may be used to qualify an attribute.

typeAttributeTrailadded inv0.17.0

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

AttributeTrail specifies a variable with an optional qualifier path. An attribute value is expected tocorrespond to an AbsoluteAttribute, meaning a field selection which starts with a top-level variable.

The qualifer path elements adhere to the AttributeQualifier type constraint.

funcNewAttributeTrailadded inv0.17.0

func NewAttributeTrail(variablestring) *AttributeTrail

NewAttributeTrail creates a new simple attribute from a variable name.

funcQualifyAttributeadded inv0.17.0

func QualifyAttribute[TAttributeQualifier](attr *AttributeTrail, qualifier T) *AttributeTrail

QualifyAttribute qualifies an attribute using a valid AttributeQualifier type.

func (*AttributeTrail)Equaladded inv0.17.0

func (a *AttributeTrail) Equal(other *AttributeTrail)bool

Equal returns whether two attribute values have the same variable name and qualifier paths.

func (*AttributeTrail)QualifierPathadded inv0.17.0

func (a *AttributeTrail) QualifierPath() []any

QualifierPath returns the optional set of qualifying fields or indices applied to the variable.

func (*AttributeTrail)Stringadded inv0.17.0

func (a *AttributeTrail) String()string

String returns the string representation of the Attribute.

func (*AttributeTrail)Variableadded inv0.17.0

func (a *AttributeTrail) Variable()string

Variable returns the variable name associated with the attribute.

typeBool

type Boolbool

Bool type that implements ref.Val and supports comparison and negation.

func (Bool)Compare

func (bBool) Compare(otherref.Val)ref.Val

Compare implements the traits.Comparer interface method.

func (Bool)ConvertToNative

func (bBool) ConvertToNative(typeDescreflect.Type) (any,error)

ConvertToNative implements the ref.Val interface method.

func (Bool)ConvertToType

func (bBool) ConvertToType(typeValref.Type)ref.Val

ConvertToType implements the ref.Val interface method.

func (Bool)Equal

func (bBool) Equal(otherref.Val)ref.Val

Equal implements the ref.Val interface method.

func (Bool)IsZeroValueadded inv0.13.0

func (bBool) IsZeroValue()bool

IsZeroValue returns true if the boolean value is false.

func (Bool)Negate

func (bBool) Negate()ref.Val

Negate implements the traits.Negater interface method.

func (Bool)Type

func (bBool) Type()ref.Type

Type implements the ref.Val interface method.

func (Bool)Value

func (bBool) Value()any

Value implements the ref.Val interface method.

typeBytes

type Bytes []byte

Bytes type that implements ref.Val and supports add, compare, and sizeoperations.

func (Bytes)Add

func (bBytes) Add(otherref.Val)ref.Val

Add implements traits.Adder interface method by concatenating byte sequences.

func (Bytes)Compare

func (bBytes) Compare(otherref.Val)ref.Val

Compare implements traits.Comparer interface method by lexicographic ordering.

func (Bytes)ConvertToNative

func (bBytes) ConvertToNative(typeDescreflect.Type) (any,error)

ConvertToNative implements the ref.Val interface method.

func (Bytes)ConvertToType

func (bBytes) ConvertToType(typeValref.Type)ref.Val

ConvertToType implements the ref.Val interface method.

func (Bytes)Equal

func (bBytes) Equal(otherref.Val)ref.Val

Equal implements the ref.Val interface method.

func (Bytes)IsZeroValueadded inv0.13.0

func (bBytes) IsZeroValue()bool

IsZeroValue returns true if the byte array is empty.

func (Bytes)Size

func (bBytes) Size()ref.Val

Size implements the traits.Sizer interface method.

func (Bytes)Type

func (bBytes) Type()ref.Type

Type implements the ref.Val interface method.

func (Bytes)Value

func (bBytes) Value()any

Value implements the ref.Val interface method.

typeDouble

type Doublefloat64

Double type that implements ref.Val, comparison, and mathematicaloperations.

func (Double)Add

func (dDouble) Add(otherref.Val)ref.Val

Add implements traits.Adder.Add.

func (Double)Compare

func (dDouble) Compare(otherref.Val)ref.Val

Compare implements traits.Comparer.Compare.

func (Double)ConvertToNative

func (dDouble) ConvertToNative(typeDescreflect.Type) (any,error)

ConvertToNative implements ref.Val.ConvertToNative.

func (Double)ConvertToType

func (dDouble) ConvertToType(typeValref.Type)ref.Val

ConvertToType implements ref.Val.ConvertToType.

func (Double)Divide

func (dDouble) Divide(otherref.Val)ref.Val

Divide implements traits.Divider.Divide.

func (Double)Equal

func (dDouble) Equal(otherref.Val)ref.Val

Equal implements ref.Val.Equal.

func (Double)IsZeroValueadded inv0.13.0

func (dDouble) IsZeroValue()bool

IsZeroValue returns true if double value is 0.0

func (Double)Multiply

func (dDouble) Multiply(otherref.Val)ref.Val

Multiply implements traits.Multiplier.Multiply.

func (Double)Negate

func (dDouble) Negate()ref.Val

Negate implements traits.Negater.Negate.

func (Double)Subtract

func (dDouble) Subtract(subtrahendref.Val)ref.Val

Subtract implements traits.Subtractor.Subtract.

func (Double)Type

func (dDouble) Type()ref.Type

Type implements ref.Val.Type.

func (Double)Value

func (dDouble) Value()any

Value implements ref.Val.Value.

typeDuration

type Duration struct {time.Duration}

Duration type that implements ref.Val and supports add, compare, negate,and subtract operators. This type is also a receiver which means it canparticipate in dispatch to receiver functions.

func (Duration)Add

func (dDuration) Add(otherref.Val)ref.Val

Add implements traits.Adder.Add.

func (Duration)Compare

func (dDuration) Compare(otherref.Val)ref.Val

Compare implements traits.Comparer.Compare.

func (Duration)ConvertToNative

func (dDuration) ConvertToNative(typeDescreflect.Type) (any,error)

ConvertToNative implements ref.Val.ConvertToNative.

func (Duration)ConvertToType

func (dDuration) ConvertToType(typeValref.Type)ref.Val

ConvertToType implements ref.Val.ConvertToType.

func (Duration)Equal

func (dDuration) Equal(otherref.Val)ref.Val

Equal implements ref.Val.Equal.

func (Duration)IsZeroValueadded inv0.13.0

func (dDuration) IsZeroValue()bool

IsZeroValue returns true if the duration value is zero

func (Duration)Negate

func (dDuration) Negate()ref.Val

Negate implements traits.Negater.Negate.

func (Duration)Receive

func (dDuration) Receive(functionstring, overloadstring, args []ref.Val)ref.Val

Receive implements traits.Receiver.Receive.

func (Duration)Subtract

func (dDuration) Subtract(subtrahendref.Val)ref.Val

Subtract implements traits.Subtractor.Subtract.

func (Duration)Type

func (dDuration) Type()ref.Type

Type implements ref.Val.Type.

func (Duration)Value

func (dDuration) Value()any

Value implements ref.Val.Value.

typeErr

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

Err type which extends the built-in go error and implements ref.Val.

func (*Err)ConvertToNative

func (e *Err) ConvertToNative(typeDescreflect.Type) (any,error)

ConvertToNative implements ref.Val.ConvertToNative.

func (*Err)ConvertToType

func (e *Err) ConvertToType(typeValref.Type)ref.Val

ConvertToType implements ref.Val.ConvertToType.

func (*Err)Equal

func (e *Err) Equal(otherref.Val)ref.Val

Equal implements ref.Val.Equal.

func (*Err)Isadded inv0.13.0

func (e *Err) Is(targeterror)bool

Is implements errors.Is.

func (*Err)NodeIDadded inv0.19.0

func (e *Err) NodeID()int64

NodeID returns the AST node ID of the expression that returned the error.

func (*Err)String

func (e *Err) String()string

String implements fmt.Stringer.

func (*Err)Type

func (e *Err) Type()ref.Type

Type implements ref.Val.Type.

func (*Err)Unwrapadded inv0.17.0

func (e *Err) Unwrap()error

Unwrap implements errors.Unwrap.

func (*Err)Value

func (e *Err) Value()any

Value implements ref.Val.Value.

typeErroradded inv0.14.0

type Error interface {errorref.Val}

Error interface which allows types types.Err values to be treated as error values.

typeFieldTypeadded inv0.17.0

type FieldType struct {// Type of the field as a CEL native type value.Type *Type// IsSet indicates whether the field is set on an input object.IsSetref.FieldTester// GetFrom retrieves the field value on the input object, if set.GetFromref.FieldGetter}

FieldType represents a field's type value and whether that field supports presence detection.

typeInt

type Intint64

Int type that implements ref.Val as well as comparison and math operators.

func (Int)Add

func (iInt) Add(otherref.Val)ref.Val

Add implements traits.Adder.Add.

func (Int)Compare

func (iInt) Compare(otherref.Val)ref.Val

Compare implements traits.Comparer.Compare.

func (Int)ConvertToNative

func (iInt) ConvertToNative(typeDescreflect.Type) (any,error)

ConvertToNative implements ref.Val.ConvertToNative.

func (Int)ConvertToType

func (iInt) ConvertToType(typeValref.Type)ref.Val

ConvertToType implements ref.Val.ConvertToType.

func (Int)Divide

func (iInt) Divide(otherref.Val)ref.Val

Divide implements traits.Divider.Divide.

func (Int)Equal

func (iInt) Equal(otherref.Val)ref.Val

Equal implements ref.Val.Equal.

func (Int)IsZeroValueadded inv0.13.0

func (iInt) IsZeroValue()bool

IsZeroValue returns true if integer is equal to 0

func (Int)Modulo

func (iInt) Modulo(otherref.Val)ref.Val

Modulo implements traits.Modder.Modulo.

func (Int)Multiply

func (iInt) Multiply(otherref.Val)ref.Val

Multiply implements traits.Multiplier.Multiply.

func (Int)Negate

func (iInt) Negate()ref.Val

Negate implements traits.Negater.Negate.

func (Int)Subtract

func (iInt) Subtract(subtrahendref.Val)ref.Val

Subtract implements traits.Subtractor.Subtract.

func (Int)Type

func (iInt) Type()ref.Type

Type implements ref.Val.Type.

func (Int)Value

func (iInt) Value()any

Value implements ref.Val.Value.

typeKindadded inv0.17.0

type Kinduint

Kind indicates a CEL type's kind which is used to differentiate quickly between simpleand complex types.

const (// UnspecifiedKind is returned when the type is nil or its kind is not specified.UnspecifiedKindKind =iota// DynKind represents a dynamic type. This kind only exists at type-check time.DynKind// AnyKind represents a google.protobuf.Any type. This kind only exists at type-check time.// Prefer DynKind to AnyKind as AnyKind has a specific meaning which is based on protobuf// well-known types.AnyKind// BoolKind represents a boolean type.BoolKind// BytesKind represents a bytes type.BytesKind// DoubleKind represents a double type.DoubleKind// DurationKind represents a CEL duration type.DurationKind// ErrorKind represents a CEL error type.ErrorKind// IntKind represents an integer type.IntKind// ListKind represents a list type.ListKind// MapKind represents a map type.MapKind// NullTypeKind represents a null type.NullTypeKind// OpaqueKind represents an abstract type which has no accessible fields.OpaqueKind// StringKind represents a string type.StringKind// StructKind represents a structured object with typed fields.StructKind// TimestampKind represents a a CEL time type.TimestampKind// TypeKind represents the CEL type.TypeKind// TypeParamKind represents a parameterized type whose type name will be resolved at type-check time, if possible.TypeParamKind// UintKind represents a uint type.UintKind// UnknownKind represents an unknown value type.UnknownKind)

typeNull

Null type implementation.

func (Null)ConvertToNative

func (nNull) ConvertToNative(typeDescreflect.Type) (any,error)

ConvertToNative implements ref.Val.ConvertToNative.

func (Null)ConvertToType

func (nNull) ConvertToType(typeValref.Type)ref.Val

ConvertToType implements ref.Val.ConvertToType.

func (Null)Equal

func (nNull) Equal(otherref.Val)ref.Val

Equal implements ref.Val.Equal.

func (Null)IsZeroValueadded inv0.13.0

func (nNull) IsZeroValue()bool

IsZeroValue returns true as null always represents an absent value.

func (Null)Type

func (nNull) Type()ref.Type

Type implements ref.Val.Type.

func (Null)Value

func (nNull) Value()any

Value implements ref.Val.Value.

typeOptionaladded inv0.13.0

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

Optional value which points to a value if non-empty.

funcOptionalOfadded inv0.13.0

func OptionalOf(valueref.Val) *Optional

OptionalOf returns an optional value which wraps a concrete CEL value.

func (*Optional)ConvertToNativeadded inv0.13.0

func (o *Optional) ConvertToNative(typeDescreflect.Type) (any,error)

ConvertToNative implements the ref.Val interface method.

func (*Optional)ConvertToTypeadded inv0.13.0

func (o *Optional) ConvertToType(typeValref.Type)ref.Val

ConvertToType implements the ref.Val interface method.

func (*Optional)Equaladded inv0.13.0

func (o *Optional) Equal(otherref.Val)ref.Val

Equal determines whether the values contained by two optional values are equal.

func (*Optional)GetValueadded inv0.13.0

func (o *Optional) GetValue()ref.Val

GetValue returns the wrapped value contained in the optional.

func (*Optional)HasValueadded inv0.13.0

func (o *Optional) HasValue()bool

HasValue returns true if the optional has a value.

func (*Optional)Stringadded inv0.13.0

func (o *Optional) String()string

func (*Optional)Typeadded inv0.13.0

func (o *Optional) Type()ref.Type

Type implements the ref.Val interface method.

func (*Optional)Valueadded inv0.13.0

func (o *Optional) Value()any

Value returns the underlying 'Value()' of the wrapped value, if present.

typeProvideradded inv0.17.0

type Provider interface {// EnumValue returns the numeric value of the given enum value name.EnumValue(enumNamestring)ref.Val// FindIdent takes a qualified identifier name and returns a ref.Val if one exists.FindIdent(identNamestring) (ref.Val,bool)// FindStructType returns the Type give a qualified type name.//// For historical reasons, only struct types are expected to be returned through this// method, and the type values are expected to be wrapped in a TypeType instance using// TypeTypeWithParam(<structType>).//// Returns false if not found.FindStructType(structTypestring) (*Type,bool)// FindStructFieldNames returns thet field names associated with the type, if the type// is found.FindStructFieldNames(structTypestring) ([]string,bool)// FieldStructFieldType returns the field type for a checked type value. Returns// false if the field could not be found.FindStructFieldType(structType, fieldNamestring) (*FieldType,bool)// NewValue creates a new type value from a qualified name and map of field// name to value.//// Note, for each value, the Val.ConvertToNative function will be invoked// to convert the Val to the field's native type. If an error occurs during// conversion, the NewValue will be a types.Err.NewValue(structTypestring, fields map[string]ref.Val)ref.Val}

Provider specifies functions for creating new object instances and for resolvingenum values by name.

typeRegistryadded inv0.17.0

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

Registry provides type information for a set of registered types.

funcNewEmptyRegistryadded inv0.4.0

func NewEmptyRegistry() *Registry

NewEmptyRegistry returns a registry which is completely unconfigured.

funcNewRegistryadded inv0.2.0

func NewRegistry(types ...proto.Message) (*Registry,error)

NewRegistry accepts a list of proto message instances and returns a typeprovider which can create new instances of the provided message or anymessage that proto depends upon in its FileDescriptor.

func (*Registry)Copyadded inv0.17.0

func (p *Registry) Copy() *Registry

Copy copies the current state of the registry into its own memory space.

func (*Registry)EnumValueadded inv0.17.0

func (p *Registry) EnumValue(enumNamestring)ref.Val

EnumValue returns the numeric value of the given enum value name.

func (*Registry)FindFieldTypedeprecatedadded inv0.17.0

func (p *Registry) FindFieldType(structType, fieldNamestring) (*ref.FieldType,bool)

FindFieldType returns the field type for a checked type value. Returns false ifthe field could not be found.

Deprecated: use FindStructFieldType

func (*Registry)FindIdentadded inv0.17.0

func (p *Registry) FindIdent(identNamestring) (ref.Val,bool)

FindIdent takes a qualified identifier name and returns a ref.Val if one exists.

func (*Registry)FindStructFieldNamesadded inv0.17.2

func (p *Registry) FindStructFieldNames(structTypestring) ([]string,bool)

FindStructFieldNames returns the set of field names for the given struct type,if the type exists in the registry.

func (*Registry)FindStructFieldTypeadded inv0.17.0

func (p *Registry) FindStructFieldType(structType, fieldNamestring) (*FieldType,bool)

FindStructFieldType returns the field type for a checked type value. Returnsfalse if the field could not be found.

func (*Registry)FindStructTypeadded inv0.17.0

func (p *Registry) FindStructType(structTypestring) (*Type,bool)

FindStructType returns the Type give a qualified type name.

For historical reasons, only struct types are expected to be returned through thismethod, and the type values are expected to be wrapped in a TypeType instance usingTypeTypeWithParam(<structType>).

Returns false if not found.

func (*Registry)FindTypedeprecatedadded inv0.17.0

func (p *Registry) FindType(structTypestring) (*exprpb.Type,bool)

FindType looks up the Type given a qualified typeName. Returns false if not found.

Deprecated: use FindStructType

func (*Registry)NativeToValueadded inv0.17.0

func (p *Registry) NativeToValue(valueany)ref.Val

NativeToValue converts various "native" types to ref.Val with this specific implementationproviding support for custom proto-based types.

This method should be the inverse of ref.Val.ConvertToNative.

func (*Registry)NewValueadded inv0.17.0

func (p *Registry) NewValue(structTypestring, fields map[string]ref.Val)ref.Val

NewValue creates a new type value from a qualified name and map of fieldname to value.

Note, for each value, the Val.ConvertToNative function will be invokedto convert the Val to the field's native type. If an error occurs duringconversion, the NewValue will be a types.Err.

func (*Registry)RegisterDescriptoradded inv0.17.0

func (p *Registry) RegisterDescriptor(fileDescprotoreflect.FileDescriptor)error

RegisterDescriptor registers the contents of a protocol buffer `FileDescriptor`.

func (*Registry)RegisterMessageadded inv0.17.0

func (p *Registry) RegisterMessage(messageproto.Message)error

RegisterMessage registers a protocol buffer message and its dependencies.

func (*Registry)RegisterTypeadded inv0.17.0

func (p *Registry) RegisterType(types ...ref.Type)error

RegisterType registers a type value with the provider which ensures the provider is aware of how tomap the type to an identifier.

If the `ref.Type` value is a `*types.Type` it will be registered directly by its runtime type name.If the `ref.Type` value is not a `*types.Type` instance, a `*types.Type` instance which reflects thetraits present on the input and the runtime type name. By default this foreign type will be treatedas a types.StructKind. To avoid potential issues where the `ref.Type` values does not match thegenerated `*types.Type` instance, consider always using the `*types.Type` to represent type extensionsto CEL, even when they're not based on protobuf types.

typeString

type Stringstring

String type implementation which supports addition, comparison, matching,and size functions.

func (String)Add

func (sString) Add(otherref.Val)ref.Val

Add implements traits.Adder.Add.

func (String)Compare

func (sString) Compare(otherref.Val)ref.Val

Compare implements traits.Comparer.Compare.

func (String)ConvertToNative

func (sString) ConvertToNative(typeDescreflect.Type) (any,error)

ConvertToNative implements ref.Val.ConvertToNative.

func (String)ConvertToType

func (sString) ConvertToType(typeValref.Type)ref.Val

ConvertToType implements ref.Val.ConvertToType.

func (String)Equal

func (sString) Equal(otherref.Val)ref.Val

Equal implements ref.Val.Equal.

func (String)IsZeroValueadded inv0.13.0

func (sString) IsZeroValue()bool

IsZeroValue returns true if the string is empty.

func (String)Match

func (sString) Match(patternref.Val)ref.Val

Match implements traits.Matcher.Match.

func (String)Receive

func (sString) Receive(functionstring, overloadstring, args []ref.Val)ref.Val

Receive implements traits.Receiver.Receive.

func (String)Size

func (sString) Size()ref.Val

Size implements traits.Sizer.Size.

func (String)Type

func (sString) Type()ref.Type

Type implements ref.Val.Type.

func (String)Value

func (sString) Value()any

Value implements ref.Val.Value.

typeTimestamp

type Timestamp struct {time.Time}

Timestamp type implementation which supports add, compare, and subtractoperations. Timestamps are also capable of participating in dynamicfunction dispatch to instance methods.

func (Timestamp)Add

func (tTimestamp) Add(otherref.Val)ref.Val

Add implements traits.Adder.Add.

func (Timestamp)Compare

func (tTimestamp) Compare(otherref.Val)ref.Val

Compare implements traits.Comparer.Compare.

func (Timestamp)ConvertToNative

func (tTimestamp) ConvertToNative(typeDescreflect.Type) (any,error)

ConvertToNative implements ref.Val.ConvertToNative.

func (Timestamp)ConvertToType

func (tTimestamp) ConvertToType(typeValref.Type)ref.Val

ConvertToType implements ref.Val.ConvertToType.

func (Timestamp)Equal

func (tTimestamp) Equal(otherref.Val)ref.Val

Equal implements ref.Val.Equal.

func (Timestamp)IsZeroValueadded inv0.13.0

func (tTimestamp) IsZeroValue()bool

IsZeroValue returns true if the timestamp is epoch 0.

func (Timestamp)Receive

func (tTimestamp) Receive(functionstring, overloadstring, args []ref.Val)ref.Val

Receive implements traits.Receiver.Receive.

func (Timestamp)Subtract

func (tTimestamp) Subtract(subtrahendref.Val)ref.Val

Subtract implements traits.Subtractor.Subtract.

func (Timestamp)Type

func (tTimestamp) Type()ref.Type

Type implements ref.Val.Type.

func (Timestamp)Value

func (tTimestamp) Value()any

Value implements ref.Val.Value.

typeTypeadded inv0.17.0

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

Type holds a reference to a runtime type with an optional type-checked set of type parameters.

funcAlphaProtoAsTypeadded inv0.22.0

func AlphaProtoAsType(t *exprpb.Type) (*Type,error)

AlphaProtoAsType converts a CEL v1alpha1.Type protobuf type to a CEL-native type representation.

funcExprTypeToTypeadded inv0.17.0

func ExprTypeToType(t *exprpb.Type) (*Type,error)

ExprTypeToType converts a protobuf CEL type representation to a CEL-native type representation.

funcNewListTypeadded inv0.17.0

func NewListType(elemType *Type) *Type

NewListType creates an instances of a list type value with the provided element type.

funcNewMapTypeadded inv0.17.0

func NewMapType(keyType, valueType *Type) *Type

NewMapType creates an instance of a map type value with the provided key and value types.

funcNewNullableTypeadded inv0.17.0

func NewNullableType(wrapped *Type) *Type

NewNullableType creates an instance of a nullable type with the provided wrapped type.

Note: only primitive types are supported as wrapped types.

funcNewObjectTypeadded inv0.17.0

func NewObjectType(typeNamestring, traits ...int) *Type

NewObjectType creates a type reference to an externally defined type, e.g. a protobuf message type.

An object type is assumed to support field presence testing and field indexing. Additionally, thetype may also indicate additional traits through the use of the optional traits vararg argument.

funcNewObjectTypeValuedeprecated

func NewObjectTypeValue(typeNamestring) *Type

NewObjectTypeValue creates a type reference to an externally defined type.

Deprecated: use cel.ObjectType(typeName)

funcNewOpaqueTypeadded inv0.17.0

func NewOpaqueType(namestring, params ...*Type) *Type

NewOpaqueType creates an abstract parameterized type with a given name.

funcNewOptionalTypeadded inv0.17.0

func NewOptionalType(param *Type) *Type

NewOptionalType creates an abstract parameterized type instance corresponding to CEL's notion of optional.

funcNewTypeParamTypeadded inv0.17.0

func NewTypeParamType(paramNamestring) *Type

NewTypeParamType creates a parameterized type instance.

funcNewTypeTypeWithParamadded inv0.17.0

func NewTypeTypeWithParam(param *Type) *Type

NewTypeTypeWithParam creates a type with a type parameter.Used for type-checking purposes, but equivalent to TypeType otherwise.

funcNewTypeValuedeprecated

func NewTypeValue(typeNamestring, traits ...int) *Type

NewTypeValue creates an opaque type which has a set of optional type traits as defined inthe common/types/traits package.

Deprecated: use cel.ObjectType(typeName, traits)

funcProtoAsTypeadded inv0.22.0

func ProtoAsType(t *celpb.Type) (*Type,error)

ProtoAsType converts a canonical CEL celpb.Type protobuf type to a CEL-native type representation.

func (*Type)ConvertToNativeadded inv0.17.0

func (t *Type) ConvertToNative(typeDescreflect.Type) (any,error)

ConvertToNative implements ref.Val.ConvertToNative.

func (*Type)ConvertToTypeadded inv0.17.0

func (t *Type) ConvertToType(typeValref.Type)ref.Val

ConvertToType implements ref.Val.ConvertToType.

func (*Type)DeclaredTypeNameadded inv0.17.0

func (t *Type) DeclaredTypeName()string

DeclaredTypeName indicates the fully qualified and parameterized type-check type name.

func (*Type)Equaladded inv0.17.0

func (t *Type) Equal(otherref.Val)ref.Val

Equal indicates whether two types have the same runtime type name.

The name Equal is a bit of a misnomer, but for historical reasons, this is theruntime behavior. For a more accurate definition see IsType().

func (*Type)HasTraitadded inv0.17.0

func (t *Type) HasTrait(traitint)bool

HasTrait implements the ref.Type interface method.

func (*Type)IsAssignableRuntimeTypeadded inv0.17.0

func (t *Type) IsAssignableRuntimeType(valref.Val)bool

IsAssignableRuntimeType determines whether the current type is runtime assignable from the input runtimeType.

At runtime, parameterized types are erased and so a function which type-checks to support a map(string, string)will have a runtime assignable type of a map.

func (*Type)IsAssignableTypeadded inv0.17.0

func (t *Type) IsAssignableType(fromType *Type)bool

IsAssignableType determines whether the current type is type-check assignable from the input fromType.

func (*Type)IsEquivalentTypeadded inv0.17.0

func (t *Type) IsEquivalentType(other *Type)bool

IsEquivalentType indicates whether two types are equivalent. This check ignores type parameter type names.

func (*Type)IsExactTypeadded inv0.17.0

func (t *Type) IsExactType(other *Type)bool

IsExactType indicates whether the two types are exactly the same. This check also verifies type parameter type names.

func (*Type)Kindadded inv0.17.0

func (t *Type) Kind()Kind

Kind indicates general category of the type.

func (*Type)Parametersadded inv0.17.0

func (t *Type) Parameters() []*Type

Parameters returns the list of type parameters if set.

For ListKind, Parameters()[0] represents the list element typeFor MapKind, Parameters()[0] represents the map key type, and Parameters()[1] represents the mapvalue type.

func (*Type)Stringadded inv0.17.0

func (t *Type) String()string

String returns a human-readable definition of the type name.

func (*Type)Typeadded inv0.17.0

func (t *Type) Type()ref.Type

Type implements the ref.Val interface method.

func (*Type)TypeNameadded inv0.17.0

func (t *Type) TypeName()string

TypeName returns the type-erased fully qualified runtime type name.

TypeName implements the ref.Type interface method.

func (*Type)Valueadded inv0.17.0

func (t *Type) Value()any

Value implements the ref.Val interface method.

func (*Type)WithTraitsadded inv0.19.0

func (t *Type) WithTraits(traitsint) *Type

WithTraits creates a copy of the current Type and sets the trait mask to the traits parameter.

This method should be used with Opaque types where the type acts like a container, e.g. vector.

typeUint

type Uintuint64

Uint type implementation which supports comparison and math operators.

func (Uint)Add

func (iUint) Add(otherref.Val)ref.Val

Add implements traits.Adder.Add.

func (Uint)Compare

func (iUint) Compare(otherref.Val)ref.Val

Compare implements traits.Comparer.Compare.

func (Uint)ConvertToNative

func (iUint) ConvertToNative(typeDescreflect.Type) (any,error)

ConvertToNative implements ref.Val.ConvertToNative.

func (Uint)ConvertToType

func (iUint) ConvertToType(typeValref.Type)ref.Val

ConvertToType implements ref.Val.ConvertToType.

func (Uint)Divide

func (iUint) Divide(otherref.Val)ref.Val

Divide implements traits.Divider.Divide.

func (Uint)Equal

func (iUint) Equal(otherref.Val)ref.Val

Equal implements ref.Val.Equal.

func (Uint)IsZeroValueadded inv0.13.0

func (iUint) IsZeroValue()bool

IsZeroValue returns true if the uint is zero.

func (Uint)Modulo

func (iUint) Modulo(otherref.Val)ref.Val

Modulo implements traits.Modder.Modulo.

func (Uint)Multiply

func (iUint) Multiply(otherref.Val)ref.Val

Multiply implements traits.Multiplier.Multiply.

func (Uint)Subtract

func (iUint) Subtract(subtrahendref.Val)ref.Val

Subtract implements traits.Subtractor.Subtract.

func (Uint)Type

func (iUint) Type()ref.Type

Type implements ref.Val.Type.

func (Uint)Value

func (iUint) Value()any

Value implements ref.Val.Value.

typeUnknown

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

Unknown type which collects expression ids which caused the current value to become unknown.

funcMaybeMergeUnknownsadded inv0.17.0

func MaybeMergeUnknowns(valref.Val, unk *Unknown) (*Unknown,bool)

MaybeMergeUnknowns determines whether an input value and another, possibly nil, unknown will producean unknown result.

If the input `val` is another Unknown, then the result will be the merge of the `val` and the input`unk`. If the `val` is not unknown, then the result will depend on whether the input `unk` is nil.If both values are non-nil and unknown, then the return value will be a merge of both unknowns.

funcMergeUnknownsadded inv0.17.0

func MergeUnknowns(unk1, unk2 *Unknown) *Unknown

MergeUnknowns combines two unknown values into a new unknown value.

funcNewUnknownadded inv0.17.0

func NewUnknown(idint64, attr *AttributeTrail) *Unknown

NewUnknown creates a new unknown at a given expression id for an attribute.

If the attribute is nil, the attribute value will be the `unspecifiedAttribute`.

func (*Unknown)Containsadded inv0.17.0

func (u *Unknown) Contains(other *Unknown)bool

Contains returns true if the input unknown is a subset of the current unknown.

func (*Unknown)ConvertToNative

func (u *Unknown) ConvertToNative(typeDescreflect.Type) (any,error)

ConvertToNative implements ref.Val.ConvertToNative.

func (*Unknown)ConvertToType

func (u *Unknown) ConvertToType(typeValref.Type)ref.Val

ConvertToType is an identity function since unknown values cannot be modified.

func (*Unknown)Equal

func (u *Unknown) Equal(otherref.Val)ref.Val

Equal is an identity function since unknown values cannot be modified.

func (*Unknown)GetAttributeTrailsadded inv0.17.1

func (u *Unknown) GetAttributeTrails(idint64) ([]*AttributeTrail,bool)

GetAttributeTrails returns the attribute trails, if present, missing for a given expression id.

func (*Unknown)IDsadded inv0.17.1

func (u *Unknown) IDs() []int64

IDs returns the set of unknown expression ids contained by this value.

Numeric identifiers are guaranteed to be in sorted order.

func (*Unknown)Stringadded inv0.17.0

func (u *Unknown) String()string

String implements the Stringer interface

func (*Unknown)Type

func (u *Unknown) Type()ref.Type

Type implements ref.Val.Type.

func (*Unknown)Value

func (u *Unknown) Value()any

Value implements ref.Val.Value.

Source Files

View all Source files

Directories

PathSynopsis
Package pb reflects over protocol buffer descriptors to generate objects that simplify type, enum, and field lookup.
Package pb reflects over protocol buffer descriptors to generate objects that simplify type, enum, and field lookup.
Package ref contains the reference interfaces used throughout the types components.
Package ref contains the reference interfaces used throughout the types components.
Package traits defines interfaces that a type may implement to participate in operator overloads and function dispatch.
Package traits defines interfaces that a type may implement to participate in operator overloads and function dispatch.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f orF : Jump to
y orY : Canonical URL
go.dev uses cookies from Google to deliver and enhance the quality of its services and to analyze traffic.Learn more.

[8]ページ先頭

©2009-2025 Movatter.jp