This repository has been archived by the owner on Mar 31, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
/
deep_clones.go
85 lines (74 loc) · 1.55 KB
/
deep_clones.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
77
78
79
80
81
82
83
84
85
package v1
func (p PropertyKey) DeepClone() *PropertyKey {
return &p
}
func (c Condition) DeepClone() *Condition {
return &c
}
func (f Filter) DeepClone() *Filter {
if f.Key != nil {
f.Key = f.Key.DeepClone()
}
if len(f.Conditions) > 0 {
conditions := f.Conditions
f.Conditions = make([]*Condition, len(conditions))
for i, c := range conditions {
f.Conditions[i] = c.DeepClone()
}
}
return &f
}
func (o OracleSpecConfiguration) DeepClone() *OracleSpecConfiguration {
if len(o.Filters) > 0 {
filters := o.Filters
o.Filters = make([]*Filter, len(filters))
for i, f := range filters {
o.Filters[i] = f.DeepClone()
}
}
return &o
}
func (o OracleSpec) DeepClone() *OracleSpec {
if len(o.PubKeys) > 0 {
pks := o.PubKeys
o.PubKeys = make([]string, len(pks))
for i, pk := range pks {
o.PubKeys[i] = pk
}
}
if len(o.Filters) > 0 {
filters := o.Filters
o.Filters = make([]*Filter, len(filters))
for i, f := range filters {
o.Filters[i] = f.DeepClone()
}
}
return &o
}
func (p Property) DeepClone() *Property {
return &p
}
func (o OracleData) DeepClone() *OracleData {
if len(o.PubKeys) > 0 {
pks := o.PubKeys
o.PubKeys = make([]string, len(pks))
for i, k := range pks {
o.PubKeys[i] = k
}
}
if len(o.Data) > 0 {
data := o.Data
o.Data = make([]*Property, len(data))
for i, d := range data {
o.Data[i] = d.DeepClone()
}
}
if len(o.MatchedSpecIds) > 0 {
ms := o.MatchedSpecIds
o.MatchedSpecIds = make([]string, len(ms))
for i, m := range ms {
o.MatchedSpecIds[i] = m
}
}
return &o
}