-
Notifications
You must be signed in to change notification settings - Fork 0
/
bag.go
65 lines (54 loc) · 1.19 KB
/
bag.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
package re
import "strings"
type Bag struct {
ops []Op
codeInfo CodeInfo
message string
internal error
kind Kind
metaData Meta
}
func (e *Bag) Chain(op Op) Error {
e.ops = append(e.ops, op)
return e
}
func (e *Bag) ChainWithMeta(op Op, meta Meta) Error {
e.ops = append(e.ops, op)
if e.metaData == nil {
e.metaData = make(Meta)
}
e.metaData[op.String()] = meta
return e
}
func (e *Bag) RawMap() map[string]interface{} {
return map[string]interface{}{
"operations": e.ops,
"internal": e.internal,
"kind": e.kind,
"code_info": e.codeInfo,
"meta_data": e.metaData,
"message": e.message,
}
}
func (e *Bag) ProcessedMap() map[string]string {
operations := make([]string, 0, len(e.ops))
for i := len(e.ops) - 1; i >= 0; i-- {
operations = append(operations, e.ops[i].String())
}
return map[string]string{
"operations": strings.Join(operations, " => "),
"internal": e.internal.Error(),
"kind": e.kind.String(),
"code_info": e.codeInfo.String(),
"meta_data": e.metaData.String(),
}
}
func (e *Bag) Kind() Kind {
return e.kind
}
func (e *Bag) Internal() error {
return e.internal
}
func (e *Bag) Message() string {
return e.message
}