forked from zalando/skipper
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcopy.go
81 lines (68 loc) · 1.68 KB
/
copy.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
package eskip
func copyArgs(a []interface{}) []interface{} {
// we don't need deep copy of the items for the supported values
c := make([]interface{}, len(a))
copy(c, a)
return c
}
// CopyPredicate creates a copy of the input predicate.
func CopyPredicate(p *Predicate) *Predicate {
if p == nil {
return nil
}
c := &Predicate{}
c.Name = p.Name
c.Args = copyArgs(p.Args)
return c
}
// CopyPredicates creates a new slice with the copy of each predicate in the input slice.
func CopyPredicates(p []*Predicate) []*Predicate {
c := make([]*Predicate, len(p))
for i, pi := range p {
c[i] = CopyPredicate(pi)
}
return c
}
// CopyFilter creates a copy of the input filter.
func CopyFilter(f *Filter) *Filter {
if f == nil {
return nil
}
c := &Filter{}
c.Name = f.Name
c.Args = copyArgs(f.Args)
return c
}
// CopyFilters creates a new slice with the copy of each filter in the input slice.
func CopyFilters(f []*Filter) []*Filter {
c := make([]*Filter, len(f))
for i, fi := range f {
c[i] = CopyFilter(fi)
}
return c
}
// Copy creates a canonical copy of the input route. See also Canonical().
func Copy(r *Route) *Route {
if r == nil {
return nil
}
r = Canonical(r)
c := &Route{}
c.Id = r.Id
c.Predicates = CopyPredicates(r.Predicates)
c.Filters = CopyFilters(r.Filters)
c.BackendType = r.BackendType
c.Backend = r.Backend
c.LBAlgorithm = r.LBAlgorithm
c.LBEndpoints = make([]string, len(r.LBEndpoints))
copy(c.LBEndpoints, r.LBEndpoints)
return c
}
// CopyRoutes creates a new slice with the canonical copy of each route in the input slice.
func CopyRoutes(r []*Route) []*Route {
c := make([]*Route, len(r))
for i, ri := range r {
c[i] = Copy(ri)
}
return c
}