forked from oam-dev/oam-go-sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
/
context.go
48 lines (41 loc) · 1.11 KB
/
context.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
package oam
type ActionContext struct {
PreActions []Action
Actions []Action
PostActions []Action
Values map[string]interface{}
}
// add actions executed before actions added through Add method
func (o *ActionContext) AddPre(a ...Action) {
o.PreActions = append(o.PreActions, a...)
}
// add actions executed before actions added through AddPost method
func (o *ActionContext) Add(a ...Action) {
o.Actions = append(o.Actions, a...)
}
func (o *ActionContext) AddPost(a ...Action) {
o.PostActions = append(o.PostActions, a...)
}
func (o *ActionContext) AddValue(k string, v interface{}) {
if o.Values == nil {
o.Values = map[string]interface{}{}
}
o.Values[k] = v
}
func (o *ActionContext) GetValue(k string) interface{} {
if o.Values == nil {
return nil
}
return o.Values[k]
}
// clear and gather all actions according to action order.
func (o *ActionContext) Gather() []Action {
var actions []Action
actions = append(actions, o.PreActions...)
o.PreActions = nil
actions = append(actions, o.Actions...)
o.Actions = nil
actions = append(actions, o.PostActions...)
o.PostActions = nil
return actions
}