func()

in lib/globals.go [40:77]


func (l globalsLib) CompileOptions() []cel.EnvOption {
	globals := make([]*expr.Decl, 0, len(l))
	for name, val := range l {
		var typ *expr.Type
		// Do times and []byte first since otherwise duration gets expressed as an
		// primitive:INT64 and []byte gets expressed as list_type:{elem_type:{dyn:{}}}.
		switch val.(type) {
		case time.Duration:
			typ = decls.Duration
		case time.Time:
			typ = decls.Timestamp
		case []byte:
			typ = decls.Bytes
		default:
			rt := reflect.TypeOf(val)
			kind := rt.Kind()
			var ok bool
			typ, ok = primativeTypeFor(kind)
			if ok {
				break
			}
			switch kind {
			case reflect.Slice, reflect.Array:
				elem, _ := primativeTypeFor(rt.Elem().Kind())
				typ = decls.NewListType(elem)
			case reflect.Map:
				key, _ := primativeTypeFor(rt.Key().Kind())
				elem, _ := primativeTypeFor(rt.Elem().Kind())
				typ = decls.NewMapType(key, elem)
			default:
				typ = decls.Dyn
			}
		}
		globals = append(globals, decls.NewVar(name, typ))
	}

	return []cel.EnvOption{cel.Declarations(globals...)}
}