Define custom datatype in cel.NewEnv

94 views
Skip to first unread message

Chirag Sharma

unread,
Jun 15, 2023, 12:13:54 AM6/15/23
to CEL Go Discussion Forum
Hi Team,
I am facing issue in including custom data type in NewEnv variables.i the following go code
I am trying to define Actor as custom datatype. but its keep on failing during compile time only. any hints to solve same.

env, err := cel.NewEnv(
cel.Variable("actor", Actor{}),
cel.Variable("request", cel.MapType(cel.StringType, cel.AnyType)),
cel.Variable("resource", cel.MapType(cel.StringType, cel.AnyType)),
)

Charith Ellawala

unread,
Jun 16, 2023, 2:25:25 AM6/16/23
to CEL Go Discussion Forum
Is your `Actor` type a protobuf? If so you can do something like this:

env, err := cel.NewEnv(cel.Types(&Actor{}), cel.Variable("actor", cel.ObjectType("your.protobuf.package.Actor"))

If it's not a protobuf, I believe you'll have to wrap it in a type that implements ref.Type and use a custom type provider. I am not too sure about the exact process there because I have only ever worked with protobuf custom types.

Reply all
Reply to author
Forward
0 new messages