Skip to content

Commit

Permalink
json will paser all numbers type to float64
Browse files Browse the repository at this point in the history
  • Loading branch information
lqiz committed Jun 1, 2020
1 parent f8edbbe commit bd8d741
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions expr.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,12 @@ func parseControlMap(controlMap map[string]interface{}) map[string]node.ValueNod
case int64:
node := node.NewIntNode(control.(int64))
nodeMap[key] = node

case float64:
// value from json will be always float64
node := node.NewIntNode(int64(control.(float64)))
nodeMap[key] = node

case string:
node := node.NewStrNode(control.(string))
nodeMap[key] = node
Expand All @@ -81,6 +87,10 @@ func eval(mem map[string]node.ValueNode, expr ast.Expr) (y node.ValueNode) {
b := eval(mem, x.Y)
op := x.Op

if a == nil || b == nil {
return node.NewBadNode(Sprintf("%+v, %+v is nil", a, b))
}

switch a.GetType() {
case node.TypeInt64:
return BinaryIntExpr{}.Invoke(a, b, op)
Expand Down

0 comments on commit bd8d741

Please sign in to comment.