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)
| 203 | // |
| 204 | // Deprecated: use FunctionDecls and VariableDecls or FromConfig instead. |
| 205 | func Declarations(decls ...*exprpb.Decl) EnvOption { |
| 206 | declOpts := []EnvOption{} |
| 207 | var err error |
| 208 | var opt EnvOption |
| 209 | // Convert the declarations to `EnvOption` values ahead of time. |
| 210 | // Surface any errors in conversion when the options are applied. |
| 211 | for _, d := range decls { |
| 212 | opt, err = ExprDeclToDeclaration(d) |
| 213 | if err != nil { |
| 214 | break |
| 215 | } |
| 216 | declOpts = append(declOpts, opt) |
| 217 | } |
| 218 | return func(e *Env) (*Env, error) { |
| 219 | if err != nil { |
| 220 | return nil, err |
| 221 | } |
| 222 | for _, o := range declOpts { |
| 223 | e, err = o(e) |
| 224 | if err != nil { |
| 225 | return nil, err |
| 226 | } |
| 227 | } |
| 228 | return e, nil |
| 229 | } |
| 230 | } |
| 231 | |
| 232 | // EagerlyValidateDeclarations ensures that any collisions between configured declarations are caught |
| 233 | // at the time of the `NewEnv` call. |