/
action.go
66 lines (56 loc) · 1.23 KB
/
action.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
package agents
import (
"github.com/TeaWeb/build/internal/teautils"
"github.com/iwind/TeaGo/logs"
"github.com/iwind/TeaGo/maps"
)
// 动作
type ActionInterface interface {
// 名称
Name() string
// 代号
Code() string
// 描述
Description() string
// 校验
Validate() error
// 执行
Run(params map[string]string) (result string, err error)
// 获取简要信息
Summary() maps.Map
}
// 获取所有的数据源信息
func AllActions() []maps.Map {
result := []maps.Map{}
for _, i := range []ActionInterface{NewScriptAction()} {
summary := i.Summary()
summary["instance"] = i
result = append(result, summary)
}
return result
}
// 查找单个数据源信息
func FindAction(code string) maps.Map {
for _, summary := range AllActions() {
if summary["code"] == code {
return summary
}
}
return nil
}
// 查找单个数据源实例
func FindActionInstance(code string, options map[string]interface{}) ActionInterface {
for _, summary := range AllActions() {
if summary["code"] == code {
instance := summary["instance"].(ActionInterface)
if options != nil {
err := teautils.MapToObjectJSON(options, instance)
if err != nil {
logs.Error(err)
}
}
return instance
}
}
return nil
}