-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathpost_execute.go
49 lines (40 loc) · 944 Bytes
/
post_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
package hype
import (
"context"
)
type PostExecuter interface {
PostExecute(ctx context.Context, d *Document, err error) error
}
func (list Nodes) PostExecute(ctx context.Context, d *Document, err error) error {
var err2 error
for _, n := range list {
if nodes, ok := n.(Nodes); ok {
err2 = nodes.PostExecute(ctx, d, err)
if err2 != nil {
return err2
}
continue
}
pe, ok := n.(PostExecuter)
if ok {
err2 = pe.PostExecute(ctx, d, err)
if err2 != nil {
return PostExecuteError{
OrigErr: err,
Err: err2,
PostExecuter: pe,
}
}
}
err2 = n.Children().PostExecute(ctx, d, err)
if err2 != nil {
// the error should already be wrapped
return err2
}
}
return err
}
type PostExecuteFn func(ctx context.Context, d *Document, err error) error
func (fn PostExecuteFn) PostExecute(ctx context.Context, d *Document, err error) error {
return fn(ctx, d, err)
}