Skip to content

abusizhishen/ruleEngine

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

51 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

规则引擎

运行方式

  • api方式,参照 cmd/api/api.go中所示
    • 提供接口添加规则
    • 提供接口输入参数并进行计算输出结果
  • 内嵌到程序中

api方式

#运行程序
go run cmd/api/api.go

#添加规则
curl -XPOST 'HTTP://127.0.0.1/add?name=compare' \
-H 'content-Type:text/plain' \
-d 'a=3;b=4;a>b'

#调用规则
 curl -XPOST 'HTTP://127.0.0.1/run' \
 -H 'content-type:application/json' \
 -d '{"name":"compare","data":{}}'

参数

{
  "name":"compare", //name参数为添加的规则名
  "data":{} //data可添加规则运行需要的额外的参数
}

运算

  • 算术运算 加减乘除
    • float64 op float64
  • 比较操作 >、>=、==、<=、<
  • 逻辑运算 &&、||、!

语句

  • if、elsif、else
  • return
    • [ ]作用域

数据类型

  • bool
  • string
  • number
    • float64
  • struct
  • map
  • array

开发工具

  • goland
  • go
  • antlr