@@ -10,14 +10,11 @@ import (
10
10
11
11
type plan struct {
12
12
order []* builder
13
- initData sets.String // the initial data required for this plan
14
- dataMap map [string ]interface {} // map of all data
13
+ initData sets.String // the initial data required for this plan
15
14
}
16
15
17
16
func (p * plan ) Run (ctx context.Context , initData ... interface {}) (Result , error ) {
18
- if p .dataMap == nil {
19
- p .dataMap = make (map [string ]interface {})
20
- }
17
+ dataMap := make (map [string ]interface {})
21
18
initialData := sets .NewString ()
22
19
for _ , inter := range initData {
23
20
if inter == nil {
@@ -32,23 +29,23 @@ func (p *plan) Run(ctx context.Context, initData ...interface{}) (Result, error)
32
29
return nil , ErrMultipleInitialData
33
30
}
34
31
initialData .Insert (name )
35
- p . dataMap [name ] = inter
32
+ dataMap [name ] = inter
36
33
}
37
34
if p .initData .Difference (initialData ).Len () > 0 {
38
35
return nil , ErrInitialDataMissing
39
36
}
40
- return p . dataMap , p .run (ctx )
37
+ return dataMap , p .run (ctx , dataMap )
41
38
}
42
39
43
- func (p * plan ) run (ctx context.Context ) error {
40
+ func (p * plan ) run (ctx context.Context , dataMap map [ string ] interface {} ) error {
44
41
for i := range p .order {
45
42
b := p .order [i ]
46
43
v := reflect .ValueOf (b .Builder )
47
44
input := make ([]reflect.Value , 1 )
48
- ctx = AddResultToCtx (ctx , p . dataMap ) // allow builders to access already built data
45
+ ctx = AddResultToCtx (ctx , dataMap ) // allow builders to access already built data
49
46
input [0 ] = reflect .ValueOf (ctx )
50
47
for _ , in := range b .In {
51
- data , ok := p . dataMap [in ]
48
+ data , ok := dataMap [in ]
52
49
if ! ok {
53
50
return errors .New ("TODO: CRITICAL" )
54
51
}
@@ -62,7 +59,7 @@ func (p *plan) run(ctx context.Context) error {
62
59
return outputs [1 ].Interface ().(error )
63
60
}
64
61
name := getStructName (outputs [0 ].Type ())
65
- p . dataMap [name ] = outputs [0 ].Interface ()
62
+ dataMap [name ] = outputs [0 ].Interface ()
66
63
}
67
64
return nil
68
65
}
0 commit comments