-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdelete.go
76 lines (60 loc) · 1.58 KB
/
delete.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
68
69
70
71
72
73
74
75
76
package ssm
import (
"reflect"
"github.com/mariotoffia/ssm/internal/asm"
"github.com/mariotoffia/ssm/internal/pms"
"github.com/mariotoffia/ssm/parser"
"github.com/mariotoffia/ssm/support"
)
func (s *Serializer) delete(v interface{},
filter *support.FieldFilters,
usage []Usage) (map[string]support.FullNameField, *parser.StructNode, error) {
if len(usage) == 0 {
if len(s.usage) > 0 {
usage = s.usage
} else {
usage = []Usage{UsePms, UseAsm}
}
}
if nil == filter {
filter = support.NewFilters()
}
tp := reflect.ValueOf(v)
prs := parser.New(s.service, s.env, s.prefix)
if _, found := find(usage, UsePms); found {
prs.RegisterTagParser("pms", pms.NewTagParser())
}
if _, found := find(usage, UseAsm); found {
prs.RegisterTagParser("asm", asm.NewTagParser())
}
for n, v := range s.parser {
prs.RegisterTagParser(n, v)
}
node, err := prs.Parse(tp)
if err != nil {
return nil, nil, err
}
var invalid map[string]support.FullNameField
if _, found := find(usage, UsePms); found {
pmsRepository, err := s.getAndConfigurePms()
if err != nil {
return nil, nil, err
}
invalid, err = pmsRepository.Delete(node, filter)
}
if _, found := find(usage, UseAsm); found {
asmRepository, err := s.getAndConfigureAsm()
if err != nil {
return nil, nil, err
}
invalid2, err := asmRepository.Delete(node, filter)
if invalid == nil && len(invalid2) > 0 {
invalid = map[string]support.FullNameField{}
}
// Merge field errors from ASM with PMS errors
for key, value := range invalid2 {
invalid[key] = value
}
}
return invalid, node, err
}