-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathpre_execute.go
58 lines (48 loc) · 1011 Bytes
/
pre_execute.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
package hype
import (
"context"
)
type PreExecuter interface {
PreExecute(ctx context.Context, d *Document) error
}
func (list Nodes) PreExecute(ctx context.Context, d *Document) error {
if d == nil {
return ErrIsNil("document")
}
var err error
for _, n := range list {
if nodes, ok := n.(Nodes); ok {
err = nodes.PreExecute(ctx, d)
if err != nil {
return err
}
continue
}
pe, ok := n.(PreExecuter)
if ok {
err = pe.PreExecute(ctx, d)
if err != nil {
return PreExecuteError{
Err: err,
Filename: d.Filename,
PreExecuter: pe,
Root: d.Root,
}
}
}
err = n.Children().PreExecute(ctx, d)
if err != nil {
return PreExecuteError{
Err: err,
Filename: d.Filename,
PreExecuter: pe,
Root: d.Root,
}
}
}
return nil
}
type PreExecuteFn func(ctx context.Context, d *Document) error
func (fn PreExecuteFn) PreExecute(ctx context.Context, d *Document) error {
return fn(ctx, d)
}