mirror of
https://github.com/passbolt/go-passbolt-cli.git
synced 2025-07-11 20:29:09 +00:00
Initialize the CEL program in a util function
This commit is contained in:
parent
f30590588e
commit
0a542bfdba
5 changed files with 35 additions and 48 deletions
23
util/cel.go
Normal file
23
util/cel.go
Normal file
|
@ -0,0 +1,23 @@
|
|||
package util
|
||||
|
||||
import "github.com/google/cel-go/cel"
|
||||
|
||||
// InitCELProgram - Initialize a CEL program with given CEL command and a set of environments
|
||||
func InitCELProgram(celCmd string, options ...cel.EnvOption) (*cel.Program, error) {
|
||||
env, err := cel.NewEnv(options...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
ast, issue := env.Compile(celCmd)
|
||||
if issue.Err() != nil {
|
||||
return nil, issue.Err()
|
||||
}
|
||||
|
||||
program, err := env.Program(ast)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &program, nil
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue