forked from kazukgw/coa
/
example_test.go
67 lines (53 loc) · 932 Bytes
/
example_test.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
package coa_test
import (
"fmt"
"github.com/winespace/coa"
)
type Context struct {
actionGroup coa.ActionGroup
}
func (c *Context) ActionGroup() coa.ActionGroup {
return c.actionGroup
}
type ActionPrint1 struct {
}
func (t1 ActionPrint1) Do(ctx coa.Context) error {
fmt.Println(1)
return nil
}
type ActionPrint2 struct {
}
func (t2 ActionPrint2) Do(ctx coa.Context) error {
fmt.Println(2)
return nil
}
type ActionPrint3 struct {
}
func (t3 ActionPrint3) Do(ctx coa.Context) error {
fmt.Println(3)
return nil
}
type ActionGroup struct {
ActionPrint1
ActionPrint2
coa.DoSelf
ActionPrint3
}
func (ag *ActionGroup) Do(ctx coa.Context) error {
fmt.Println("do")
return nil
}
func (ag *ActionGroup) HandleError(ctx coa.Context, err error) error {
// handle error
return nil
}
func Example() {
ag := &ActionGroup{}
ctx := &Context{&ActionGroup{}}
coa.Exec(ag, ctx)
// Output:
// 1
// 2
// do
// 3
}