query post v0.12.0 cel.Library construction

14 views
Skip to first unread message

Dan Kortschak

unread,
May 27, 2023, 7:08:36 PM5/27/23
to cel-go-...@googlegroups.com
Since v0.12.0 an alternative way of constructing bindings has been
available[1] and cel.Functions is now deprecated[2].

I'm going through some libs to quiet the linter warnings about the
deprecations and a question has comes up; with the new API, the
ProgramOptions method of cel.Library is no longer necessary to provide
the connections between bindings and behaviours, but there does not
appear to be any other way to bundle a set of functions into a lib
beyond the cel.Library type. Is the intended approach to just do this
```
func (lib) ProgramOptions() []cel.ProgramOption { return nil }
```
when the complete name→behaviour binding path is defined in the
CompileOptions method?

[1]https://pkg.go.dev/github.com/google/cel...@v0.15.3/cel#Function
[2]https://pkg.go.dev/github.com/google/cel...@v0.15.3/cel#Functions

Tristan Swadell

unread,
May 30, 2023, 11:42:58 AM5/30/23
to Dan Kortschak, cel-go-...@googlegroups.com
Hi Dan,

The `ProgramOptions()` are still useful for decorators and for turning on some specific runtime validation checks, but if you don't have any to specify just return an empty list. The code could probably be more robust and skip options which are nil, but in general the code expects a slice of size 0 or more.

func (lib) ProgramOptions() []cel.ProgramOption { return []cel.ProgramOption{} }

Cheers,

-Tristan

--
You received this message because you are subscribed to the Google Groups "CEL Go Discussion Forum" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cel-go-discus...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/cel-go-discuss/1f49d4bb25bee016914cf16c53481b1cdb3b652d.camel%40kortschak.io.

Dan Kortschak

unread,
May 30, 2023, 5:20:17 PM5/30/23
to cel-go-...@googlegroups.com
On Tue, 2023-05-30 at 08:42 -0700, 'Tristan Swadell' via CEL Go
Discussion Forum wrote:
> Hi Dan,
>
> The `ProgramOptions()` are still useful for decorators and for
> turning on some specific runtime validation checks, but if you don't
> have any to specify just return an empty list. The code could
> probably be more robust and skip options which are nil, but in
> general the code expects a slice of size 0 or more.
>
> func (lib) ProgramOptions() []cel.ProgramOption { return
> []cel.ProgramOption{} }
>
> Cheers,
>
> -Tristan
>

Thanks, Tristan.

From the code, a nil return should be fine. AFAICS the only call is in
func Lib(l Library) EnvOption where the return is appended to
cel.Env.progOpts, and append([]T, []T(nil)) is a valid no-op in Go.

Dan

Reply all
Reply to author
Forward
0 new messages