-
Notifications
You must be signed in to change notification settings - Fork 0
/
resource.go
117 lines (100 loc) · 3.17 KB
/
resource.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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
package common_type
type HttpRequest struct {
Method string
QueryMap map[string]string
Url string
Path string
Headers map[string][]string
Body []byte
Root bool
}
type HttpResponse struct {
Err PluginError
Headers map[string][]string
Body []byte
StatusCode int
}
type HttpContext struct {
Params map[string]string
Request *HttpRequest
Response *HttpResponse
}
type EventPublisher interface {
Subscribe(condition []string) PluginError // 不支持通配符, ex: project.task.create
SubscribeWithFilter(condition []string, filter map[string][]string) PluginError // 支持过滤条件, ex: filter: project_uuid_in:[""]
Unsubscribe(condition []string) PluginError // 支持通配符
}
type AsyncInvokeCallbackParams func(PluginError)
type Workspace interface {
CreateFile(string) PluginError
MakeDir(string) PluginError
Rename(string, string) PluginError
Remove(string) PluginError
IsExist(string) (bool, PluginError)
IsDir(string) (bool, PluginError)
Copy(string, string) PluginError
Read(string) ([]byte, PluginError)
ReadLines(string, int32, int32) ([]byte, PluginError)
WriteBytes(string, []byte) PluginError
AppendBytes(string, []byte) PluginError
WriteStrings(string, []string) PluginError
AppendStrings(string, []string) PluginError
Zip(string, []string) PluginError
UnZip(string, string) PluginError
Gz(string) PluginError
UnGz(string, string) PluginError
Hash(string) ([]byte, PluginError)
List(string) ([]string, PluginError)
AsyncCopy(string, string, AsyncInvokeCallbackParams)
AsyncZip(string, []string, AsyncInvokeCallbackParams)
AsyncUnZip(string, string, AsyncInvokeCallbackParams)
AsyncGz(string, AsyncInvokeCallbackParams)
AsyncUnGz(string, string, AsyncInvokeCallbackParams)
}
type NetworkCallBack func(*HttpResponse, PluginError)
type Network interface {
Fetch(*HttpRequest) *HttpResponse
AsyncFetch(*HttpRequest, NetworkCallBack)
}
type APICore interface {
Fetch(*HttpRequest) *HttpResponse
}
type DBCallBack func([]*RawData, []*ColumnDesc, PluginError)
type RawData struct {
Cell [][]byte
}
type ColumnDesc struct {
Index int64
Name string
Type string
}
type SysDB interface {
Select(db, sql string) ([]*RawData, []*ColumnDesc, PluginError)
AsyncSelect(db, sql string, callback DBCallBack)
Exec(db, sql string) PluginError
// Unmarshal eg:
// type User struct {
// UUID string `orm:"uuid"`
// Name string `orm:"name"`
// }
// users := make([]*User, 0)
// err = Unmarshal(rawData, colDesc, &users)
Unmarshal(rawData []*RawData, columnDesc []*ColumnDesc, v interface{}) PluginError
}
type LocalDB interface {
Select(sql string) ([]*RawData, []*ColumnDesc, PluginError)
AsyncSelect(sql string, callback DBCallBack)
// Unmarshal eg:
// type User struct {
// UUID string `orm:"uuid"`
// Name string `orm:"name"`
// }
// users := make([]*User, 0)
// err = Unmarshal(rawData, colDesc, &users)
Unmarshal(rawData []*RawData, columnDesc []*ColumnDesc, v interface{}) PluginError
Exec(sql string) PluginError
ImportSQL(sqlFilePath string) PluginError
}
type Ability interface {
Call(kind string, req []byte) ([]byte, PluginError)
}