-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathcore.go
93 lines (68 loc) · 1.92 KB
/
core.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
package running
import (
"context"
)
// Node basic unit of execution
type Node interface {
Name() string
// Run will be called when all deps solved or cluster invoke it
Run(ctx context.Context)
// Reset will be called when the node will no longer execute until the next execution plan
Reset()
}
// Cluster a class of nodes that can contain other nodes
type Cluster interface {
Node
// Inject deliver the sub-nodes, will be called when engine build the cluster
Inject(nodes []Node)
}
// Wrapper a class of nodes that can wrap other node
type Wrapper interface {
Node
Wrap(target Node)
}
// Stateful a class of nodes that need record or query state
type Stateful interface {
Node
// Bind deliver the state, should be called before engine run the node
Bind(state State)
}
// Cloneable a class of nodes that can be cloned
type Cloneable interface {
Node
// Clone self
Clone() Node
}
// Reversible a class of nodes that can be reverted
type Reversible interface {
Node
Revert(ctx context.Context)
}
// Props provide build parameters for the node builder
type Props interface {
// Get return global value of the key
Get(key string) (interface{}, bool)
//SubGet node value of the key, deliver node name as sub
SubGet(sub, key string) (interface{}, bool)
// Copy safe use of copies
Copy() Props
}
// ExportableProps can be used to lookup raw data and serialization
type ExportableProps interface {
Raw() map[string]interface{}
}
type BuildNodeFunc func(name string, props Props) (Node, error)
// State store state of nodes
type State interface {
// Query return value of the key
Query(key string) (interface{}, bool)
// Update set a new value for the key
Update(key string, value interface{})
// Transform set a new value for the key, according to the old value
Transform(key string, transform TransformStateFunc)
}
type TransformStateFunc func(from interface{}) interface{}
type Output struct {
Err error
State State
}