-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmapping.go
57 lines (50 loc) · 1.28 KB
/
mapping.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
package main
import "reflect"
// Mapping ...
type Mapping struct {
Anonym,
Config,
BPMNType map[int]string
}
// Assign maps the fields of a ReflectValue to the corresponding maps.
func (m *Mapping) Assign(v *ReflectValue) {
// Initialize the maps.
m.Anonym = make(map[int]string)
m.Config = make(map[int]string)
m.BPMNType = make(map[int]string)
// Define a mapping of field types to their corresponding maps.
fieldMap := map[reflect.Kind]map[int]string{
reflect.Bool: m.Config,
reflect.Struct: m.BPMNType,
}
anonymIndex := 0
configIndex := 0
bpmnTypeIndex := 0
// Iterate over the fields and assign them to the corresponding maps.
for _, field := range v.Fields {
if field.Anonymous {
m.Anonym[anonymIndex] = field.Name
anonymIndex++
} else {
// Get the map for the field type.
fieldMapForType, ok := fieldMap[field.Type.Kind()]
if !ok {
// If the field type is not recognized, check if it's a BPMN struct.
if field.Type.Name() == "BPMN" {
m.BPMNType[bpmnTypeIndex] = field.Name
bpmnTypeIndex++
}
} else {
// Assign the field to the corresponding map.
fieldMapForType[configIndex] = field.Name
configIndex++
}
}
}
}
func (m *Mapping) Cleanup() {
// Clear maps and slices
m.BPMNType = nil
m.Config = nil
m.Anonym = nil
}