NewCustomEnv creates a custom program environment which is not automatically configured with the standard library of functions and macros documented in the CEL spec. The purpose for using a custom environment might be for subsetting the standard library produced by the cel.StdLib() function. Subset
(opts ...EnvOption)
| 382 | // See the EnvOption helper functions for the options that can be used to configure the |
| 383 | // environment. |
| 384 | func NewCustomEnv(opts ...EnvOption) (*Env, error) { |
| 385 | registry, err := types.NewRegistry() |
| 386 | if err != nil { |
| 387 | return nil, err |
| 388 | } |
| 389 | return (&Env{ |
| 390 | variables: []*decls.VariableDecl{}, |
| 391 | functions: map[string]*decls.FunctionDecl{}, |
| 392 | macros: []parser.Macro{}, |
| 393 | Container: containers.DefaultContainer, |
| 394 | adapter: registry, |
| 395 | provider: registry, |
| 396 | features: map[int]bool{}, |
| 397 | appliedFeatures: map[int]bool{}, |
| 398 | limits: map[limitID]int{}, |
| 399 | libraries: map[string]SingletonLibrary{}, |
| 400 | validators: []ASTValidator{}, |
| 401 | progOpts: []ProgramOption{}, |
| 402 | costOptions: []checker.CostOption{}, |
| 403 | }).configure(opts) |
| 404 | } |
| 405 | |
| 406 | // Check performs type-checking on the input Ast and yields a checked Ast and/or set of Issues. |
| 407 | // If any `ASTValidators` are configured on the environment, they will be applied after a valid |