/
relations.go
51 lines (46 loc) · 1.33 KB
/
relations.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
package util
type ForeignRelations struct {
Consumer, ConsumerGroup, Route, Service []string
}
type Rel struct {
Consumer, ConsumerGroup, Route, Service string
}
func (relations *ForeignRelations) GetCombinations() []Rel {
var cartesianProduct []Rel
if len(relations.Consumer) > 0 {
consumers := relations.Consumer
if len(relations.Route)+len(relations.Service) > 0 {
for _, service := range relations.Service {
for _, consumer := range consumers {
cartesianProduct = append(cartesianProduct, Rel{
Service: service,
Consumer: consumer,
})
}
}
for _, route := range relations.Route {
for _, consumer := range consumers {
cartesianProduct = append(cartesianProduct, Rel{
Route: route,
Consumer: consumer,
})
}
}
} else {
for _, consumer := range relations.Consumer {
cartesianProduct = append(cartesianProduct, Rel{Consumer: consumer})
}
}
} else {
for _, consumerGroup := range relations.ConsumerGroup {
cartesianProduct = append(cartesianProduct, Rel{ConsumerGroup: consumerGroup})
}
for _, service := range relations.Service {
cartesianProduct = append(cartesianProduct, Rel{Service: service})
}
for _, route := range relations.Route {
cartesianProduct = append(cartesianProduct, Rel{Route: route})
}
}
return cartesianProduct
}