enhance: [2.4] support to execute the method which contains the ctx param (#36798)

/kind improvement
- pr: #36797

Signed-off-by: SimFG <bang.fu@zilliz.com>
pull/36803/head v2.4.13
SimFG 2024-10-11 23:17:21 +08:00 committed by GitHub
parent 0fe549adf1
commit 1d9c7462ba
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 5 additions and 2 deletions

View File

@ -19,6 +19,7 @@
package expr
import (
"context"
"fmt"
"github.com/expr-lang/expr"
@ -37,7 +38,9 @@ var (
func Init() {
v = &vm.VM{}
env = make(map[string]any)
env = map[string]any{
"ctx": context.TODO(),
}
authKey = paramtable.Get().EtcdCfg.RootPath.GetValue()
}
@ -65,7 +68,7 @@ func Exec(code, auth string) (res string, err error) {
if authKey != auth {
return "", fmt.Errorf("the expr auth is invalid")
}
program, err := expr.Compile(code, expr.Env(env))
program, err := expr.Compile(code, expr.Env(env), expr.WithContext("ctx"))
if err != nil {
log.Warn("expr compile failed", zap.String("code", code), zap.Error(err))
return "", err