diff --git a/automation/server/internal/module/common/enum/enum.go b/automation/server/internal/module/common/enum/enum.go new file mode 100644 index 0000000000000000000000000000000000000000..d59e3c444e8d55acefb6b4ba74b9a43ec8bf98f7 --- /dev/null +++ b/automation/server/internal/module/common/enum/enum.go @@ -0,0 +1,30 @@ +package enum + +import ( + "encoding/json" + "sort" +) + +type Item struct { + ID int `json:"id"` + Type string `json:"type"` +} + +type MapWrapper map[int]string + +func (m MapWrapper) MarshalJSON() ([]byte, error) { + keys := make([]int, 0, len(m)) + for k := range m { + keys = append(keys, k) + } + sort.Ints(keys) + + items := make([]Item, 0, len(keys)) + for _, k := range keys { + items = append(items, Item{ + ID: k, + Type: m[k], + }) + } + return json.Marshal(items) +} diff --git a/automation/server/internal/module/common/enum/rule/rule.go b/automation/server/internal/module/common/enum/rule/rule.go new file mode 100644 index 0000000000000000000000000000000000000000..7376ac231679fda365f53204083e318ca8327502 --- /dev/null +++ b/automation/server/internal/module/common/enum/rule/rule.go @@ -0,0 +1,26 @@ +package rule + +import "openeuler.org/PilotGo/PilotGo-plugin-automation/internal/module/common/enum" + +type Severity int + +const ( + SeverityBlock Severity = 1 + SeverityWarning Severity = 2 +) + +var SeverityMap = enum.MapWrapper{ + int(SeverityBlock): "拦截", + int(SeverityWarning): "警告", +} + +func (s Severity) String() string { + switch s { + case SeverityBlock: + return "拦截" + case SeverityWarning: + return "警告" + default: + return "未定义" + } +} diff --git a/automation/server/internal/module/common/enum/script/script.go b/automation/server/internal/module/common/enum/script/script.go new file mode 100644 index 0000000000000000000000000000000000000000..2e97d7fbd60eafae4e290a1ba4230ae6580dd926 --- /dev/null +++ b/automation/server/internal/module/common/enum/script/script.go @@ -0,0 +1,34 @@ +package script + +import "openeuler.org/PilotGo/PilotGo-plugin-automation/internal/module/common/enum" + +type ScriptType int + +const ( + Shell ScriptType = 1 + Perl ScriptType = 2 + Python ScriptType = 3 + SQL ScriptType = 4 +) + +var ScriptTypeMap = enum.MapWrapper{ + int(Shell): "Shell", + int(Perl): "Perl", + int(Python): "Python", + int(SQL): "SQL", +} + +func (s ScriptType) String() string { + switch s { + case Shell: + return "Shell" + case Perl: + return "Perl" + case Python: + return "Python" + case SQL: + return "SQL" + default: + return "未支持" + } +}