Merge remote-tracking branch 'origin/main' into multi-tenant
This commit is contained in:
@@ -25,7 +25,7 @@ func InitConfig(configFile string) {
|
||||
|
||||
// Get 获取配置信息
|
||||
//
|
||||
// Get("framework.name")
|
||||
// Get("server.port")
|
||||
func Get(key string) any {
|
||||
return v.Get(key)
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@ import (
|
||||
"go/ast"
|
||||
"go/parser"
|
||||
"go/token"
|
||||
"math"
|
||||
"regexp"
|
||||
"strconv"
|
||||
"strings"
|
||||
@@ -29,6 +30,9 @@ func CalcExpr(expr string, paramValues map[string]any) (float64, error) {
|
||||
|
||||
// expression to evaluate
|
||||
result, err := evalExpr(expr)
|
||||
if math.IsNaN(result) {
|
||||
return 0.0, err
|
||||
}
|
||||
return result, err
|
||||
}
|
||||
|
||||
@@ -87,6 +91,10 @@ func evalNode(node ast.Node) (float64, error) {
|
||||
case token.MUL:
|
||||
result = left * right
|
||||
case token.QUO:
|
||||
if right == 0 {
|
||||
return math.NaN(), fmt.Errorf("divisor cannot be zero")
|
||||
}
|
||||
|
||||
result = left / right
|
||||
}
|
||||
case *ast.BasicLit:
|
||||
|
||||
Reference in New Issue
Block a user