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)
| 361 | // See the EnvOption helper functions for the options that can be used to configure the |
| 362 | // environment. |
| 363 | func NewCustomEnv(opts ...EnvOption) (*Env, error) { |
| 364 | registry, err := types.NewProtoRegistry() |
| 365 | if err != nil { |
| 366 | return nil, err |
| 367 | } |
| 368 | return (&Env{ |
| 369 | variables: []*decls.VariableDecl{}, |
| 370 | functions: map[string]*decls.FunctionDecl{}, |
| 371 | functionBindings: []*functions.Overload{}, |
| 372 | macros: []parser.Macro{}, |
| 373 | Container: containers.DefaultContainer, |
| 374 | adapter: registry, |
| 375 | provider: registry, |
| 376 | features: map[int]bool{}, |
| 377 | appliedFeatures: map[int]bool{}, |
| 378 | limits: map[limitID]int{}, |
| 379 | libraries: map[string]SingletonLibrary{}, |
| 380 | validators: []ASTValidator{}, |
| 381 | progOpts: []ProgramOption{}, |
| 382 | costOptions: []checker.CostOption{}, |
| 383 | }).configure(opts) |
| 384 | } |
| 385 | |
| 386 | // Check performs type-checking on the input Ast and yields a checked Ast and/or set of Issues. |
| 387 | // If any `ASTValidators` are configured on the environment, they will be applied after a valid |