Documentation ¶
Index ¶
- Variables
- func NewCustomCELTypeAdapter() ref.TypeAdapter
- type Hierarchy
- func (h Hierarchy) ConvertToNative(typeDesc reflect.Type) (interface{}, error)
- func (h Hierarchy) ConvertToType(typeVal ref.Type) ref.Val
- func (h Hierarchy) Equal(other ref.Val) ref.Val
- func (h Hierarchy) Get(index ref.Val) ref.Val
- func (h Hierarchy) Receive(function, overload string, args []ref.Val) ref.Val
- func (h Hierarchy) Size() ref.Val
- func (h Hierarchy) Type() ref.Type
- func (h Hierarchy) Value() interface{}
Constants ¶
This section is empty.
Variables ¶
View Source
var ( HierarchyType = types.NewTypeValue(hierarchyTypeName, traits.IndexerType, traits.SizerType, traits.ReceiverType) HierarchyDeclrations = []*exprpb.Decl{ decls.NewFunction(hierarchyFn, decls.NewOverload(fmt.Sprintf("%s_string", hierarchyFn), []*exprpb.Type{decls.String}, hierarchyTypeExpr, ), decls.NewOverload(fmt.Sprintf("%s_string_string", hierarchyFn), []*exprpb.Type{decls.String, decls.String}, hierarchyTypeExpr, ), decls.NewOverload(fmt.Sprintf("%s_stringarray", hierarchyFn), []*exprpb.Type{decls.NewListType(decls.String)}, hierarchyTypeExpr, ), ), decls.NewFunction(overloadAncestorOf, decls.NewInstanceOverload(overloadAncestorOf, []*exprpb.Type{hierarchyTypeExpr, hierarchyTypeExpr}, decls.Bool, ), ), decls.NewFunction(overloadCommonAncestors, decls.NewInstanceOverload(overloadCommonAncestors, []*exprpb.Type{hierarchyTypeExpr, hierarchyTypeExpr}, hierarchyTypeExpr, ), ), decls.NewFunction(overloadDescendentOf, decls.NewInstanceOverload(overloadDescendentOf, []*exprpb.Type{hierarchyTypeExpr, hierarchyTypeExpr}, decls.Bool, ), ), decls.NewFunction(overloadImmediateChildOf, decls.NewInstanceOverload(overloadImmediateChildOf, []*exprpb.Type{hierarchyTypeExpr, hierarchyTypeExpr}, decls.Bool, ), ), decls.NewFunction(overloadImmediateParentOf, decls.NewInstanceOverload(overloadImmediateParentOf, []*exprpb.Type{hierarchyTypeExpr, hierarchyTypeExpr}, decls.Bool, ), ), decls.NewFunction(overloadOverlaps, decls.NewInstanceOverload(overloadOverlaps, []*exprpb.Type{hierarchyTypeExpr, hierarchyTypeExpr}, decls.Bool, ), ), decls.NewFunction(overloadSiblingOf, decls.NewInstanceOverload(overloadSiblingOf, []*exprpb.Type{hierarchyTypeExpr, hierarchyTypeExpr}, decls.Bool, ), ), decls.NewFunction(overloads.Size, decls.NewInstanceOverload(fmt.Sprintf("%s_size", hierarchyFn), []*exprpb.Type{hierarchyTypeExpr}, decls.Int, ), ), decls.NewFunction(operators.Index, decls.NewOverload(fmt.Sprintf("%s_index", hierarchyFn), []*exprpb.Type{hierarchyTypeExpr, decls.Int}, decls.String, ), ), } HierarchyOverload = &functions.Overload{ Operator: hierarchyFn, Unary: func(v ref.Val) ref.Val { switch hv := v.(type) { case Hierarchy: return hv case types.String: return Hierarchy(strings.Split(string(hv), hierarchyDelim)) case traits.Lister: hieraEls, err := hv.ConvertToNative(reflect.SliceOf(reflect.TypeOf(""))) if err != nil { return types.NewErr("failed to convert list to string slice: %v", err) } h, ok := hieraEls.([]string) if !ok { return types.NewErr("expected string slice but got %T", hieraEls) } return Hierarchy(h) default: return types.MaybeNoSuchOverloadErr(v) } }, Binary: func(v, delim ref.Val) ref.Val { vStr, ok := v.(types.String) if !ok { return types.NoSuchOverloadErr() } delimStr, ok := delim.(types.String) if !ok { return types.NoSuchOverloadErr() } return Hierarchy(strings.Split(string(vStr), string(delimStr))) }, } )
Functions ¶
func NewCustomCELTypeAdapter ¶
func NewCustomCELTypeAdapter() ref.TypeAdapter
NewCustomCELTypeAdapter provides a CEL type adaptor than can deal with json.Number values returned by Rego.
Types ¶
type Hierarchy ¶
type Hierarchy []string
Hierarchy is a type that represents a dot-separated hierarchy such as a.b.c.d.
func (Hierarchy) ConvertToNative ¶
ConvertToNative implements ref.Val.ConvertToNative.
func (Hierarchy) ConvertToType ¶
ConvertToType implements ref.Val.ConvertToType.
Click to show internal directories.
Click to hide internal directories.