Declarations option extends the declaration set configured in the environment. Note: Declarations will by default be appended to the pre-existing declaration set configured for the environment. The NewEnv call builds on top of the standard CEL declarations. For a purely custom set of declarations u
(decls ...*exprpb.Decl)
| 191 | // |
| 192 | // Deprecated: use FunctionDecls and VariableDecls or FromConfig instead. |
| 193 | func Declarations(decls ...*exprpb.Decl) EnvOption { |
| 194 | declOpts := []EnvOption{} |
| 195 | var err error |
| 196 | var opt EnvOption |
| 197 | // Convert the declarations to `EnvOption` values ahead of time. |
| 198 | // Surface any errors in conversion when the options are applied. |
| 199 | for _, d := range decls { |
| 200 | opt, err = ExprDeclToDeclaration(d) |
| 201 | if err != nil { |
| 202 | break |
| 203 | } |
| 204 | declOpts = append(declOpts, opt) |
| 205 | } |
| 206 | return func(e *Env) (*Env, error) { |
| 207 | if err != nil { |
| 208 | return nil, err |
| 209 | } |
| 210 | for _, o := range declOpts { |
| 211 | e, err = o(e) |
| 212 | if err != nil { |
| 213 | return nil, err |
| 214 | } |
| 215 | } |
| 216 | return e, nil |
| 217 | } |
| 218 | } |
| 219 | |
| 220 | // EagerlyValidateDeclarations ensures that any collisions between configured declarations are caught |
| 221 | // at the time of the `NewEnv` call. |