From 838ecdf2d3dabe731bf78a6084584752671406d7 Mon Sep 17 00:00:00 2001 From: skyhackvip <369983954@qq.com> Date: Thu, 22 Feb 2024 14:56:05 +0800 Subject: [PATCH] define const --- .gitignore | 2 ++ configs/config.go | 22 ++++++++++++---------- configs/const.go | 4 ++-- core/inode.go | 36 ++++++++++++++++++++---------------- core/matrix.go | 2 +- core/ruleset.go | 2 +- 6 files changed, 38 insertions(+), 30 deletions(-) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..d8e14f2 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +tags +dist/ diff --git a/configs/config.go b/configs/config.go index 1f8b053..535a49b 100644 --- a/configs/config.go +++ b/configs/config.go @@ -37,13 +37,6 @@ type AppConf struct { DslLoadPath string `yaml:"DslLoadPath"` } -//策略 -type Strategy struct { - Name string `yaml:"name"` - Priority int `yaml:"priority"` //越大越优先 - Score int `yaml:"score"` //策略分 -} - func LoadConfig(path string) (*Conf, error) { conf := new(Conf) file, err := ioutil.ReadFile(path) @@ -57,8 +50,17 @@ func LoadConfig(path string) (*Conf, error) { return conf, nil } +//策略 +type Strategy struct { + Name string `yaml:"name"` + Priority int `yaml:"priority"` //越大越优先 + Score int `yaml:"score"` //策略分 +} + +//keywords for execute const ( - CONSOLE = "console" - FILE = "file" - DB = "db" + CONSOLE = "console" + FILE = "file" + DB = "db" + PARALLEL = "parallel" ) diff --git a/configs/const.go b/configs/const.go index 29c74cc..b87e1fc 100644 --- a/configs/const.go +++ b/configs/const.go @@ -118,8 +118,8 @@ const ( RULESET = "ruleset" ABTEST = "abtest" CONDITIONAL = "conditional" - DECISIONTREE = "decisiontree" - DECISIONMATRIX = "decisionmatrix" + DECISIONTREE = "tree" + DECISIONMATRIX = "matrix" SCORECARD = "scorecard" ) diff --git a/core/inode.go b/core/inode.go index ce9e8b0..e7e3981 100644 --- a/core/inode.go +++ b/core/inode.go @@ -12,6 +12,10 @@ // package core +import ( + "github.com/skyhackvip/risk_engine/configs" +) + //各类型节点实现该接口 type INode interface { GetName() string @@ -51,14 +55,14 @@ const ( ) var nodeStrMap = map[NodeType]string{ - TypeStart: "start", - TypeEnd: "end", - TypeRuleset: "ruleset", - TypeAbtest: "abtest", - TypeConditional: "conditional", - TypeTree: "tree", - TypeMatrix: "matrix", - TypeScorecard: "scorecard", + TypeStart: configs.START, + TypeEnd: configs.END, + TypeRuleset: configs.RULESET, + TypeAbtest: configs.ABTEST, + TypeConditional: configs.CONDITIONAL, + TypeTree: configs.DECISIONTREE, + TypeMatrix: configs.DECISIONMATRIX, + TypeScorecard: configs.SCORECARD, } func (nodeType NodeType) String() string { @@ -66,14 +70,14 @@ func (nodeType NodeType) String() string { } var nodeTypeMap map[string]NodeType = map[string]NodeType{ - "start": TypeStart, - "end": TypeEnd, - "ruleset": TypeRuleset, - "abtest": TypeAbtest, - "conditional": TypeConditional, - "tree": TypeTree, - "matrix": TypeMatrix, - "scorecard": TypeScorecard, + configs.START: TypeStart, + configs.END: TypeEnd, + configs.RULESET: TypeRuleset, + configs.ABTEST: TypeAbtest, + configs.CONDITIONAL: TypeConditional, + configs.DECISIONTREE: TypeTree, + configs.DECISIONMATRIX: TypeMatrix, + configs.SCORECARD: TypeScorecard, } func GetNodeType(name string) NodeType { diff --git a/core/matrix.go b/core/matrix.go index 16b6be3..db713df 100644 --- a/core/matrix.go +++ b/core/matrix.go @@ -70,7 +70,7 @@ func (matrixNode MatrixNode) Parse(ctx *PipelineContext) (*NodeResult, error) { var xResult string var yResult string - if matrixNode.ExecPlan == "parallel" { //并发分组执行 + if matrixNode.ExecPlan == configs.PARALLEL { //并发分组执行 ruleMap := make(map[string][]Rule) for _, rule := range matrixNode.Rules { if rule.Kind == configs.MATRIXX { diff --git a/core/ruleset.go b/core/ruleset.go index 9813e80..620b9d0 100644 --- a/core/ruleset.go +++ b/core/ruleset.go @@ -58,7 +58,7 @@ func (rulesetNode RulesetNode) Parse(ctx *PipelineContext) (*NodeResult, error) //ruleset 批量调用特征 depends := ctx.GetFeatures(info.Depends) - if rulesetNode.ExecPlan == "parallel" { //并发执行规则 + if rulesetNode.ExecPlan == configs.PARALLEL { //并发执行规则 var wg sync.WaitGroup var mu sync.Mutex for _, rule := range rulesetNode.Rules {