Skip to content
Snippets Groups Projects
Commit 399360bd authored by Kali Kaneko's avatar Kali Kaneko
Browse files

fix uninitialized byCity bug

parent 34e24135
Branches
Tags
No related merge requests found
...@@ -79,9 +79,14 @@ func (p *gatewayPool) populateCityList() { ...@@ -79,9 +79,14 @@ func (p *gatewayPool) populateCityList() {
func (p *gatewayPool) getCities() []string { func (p *gatewayPool) getCities() []string {
c := make([]string, 0) c := make([]string, 0)
for city, _ := range p.byCity { if p == nil || p.byCity == nil || len(p.byCity) == 0 {
return c
}
if len(p.byCity) != 0 {
for city := range p.byCity {
c = append(c, city) c = append(c, city)
} }
}
return c return c
} }
...@@ -196,9 +201,8 @@ func (p *gatewayPool) getBest(transport string, tz, max int) ([]Gateway, error) ...@@ -196,9 +201,8 @@ func (p *gatewayPool) getBest(transport string, tz, max int) ([]Gateway, error)
func (p *gatewayPool) getAll(transport string, tz int) ([]Gateway, error) { func (p *gatewayPool) getAll(transport string, tz int) ([]Gateway, error) {
if len(p.recommended) != 0 { if len(p.recommended) != 0 {
return p.getGatewaysFromMenshen(transport, 999) return p.getGatewaysFromMenshen(transport, 999)
} else {
return p.getGatewaysByTimezone(transport, tz, 999)
} }
return p.getGatewaysByTimezone(transport, tz, 999)
} }
/* picks at most max gateways, filtering by transport, from the ordered list menshen returned */ /* picks at most max gateways, filtering by transport, from the ordered list menshen returned */
...@@ -235,9 +239,8 @@ func (p *gatewayPool) getGatewaysByTimezone(transport string, tzOffsetHours, max ...@@ -235,9 +239,8 @@ func (p *gatewayPool) getGatewaysByTimezone(transport string, tzOffsetHours, max
if err != nil { if err != nil {
log.Printf("Error sorting gateways: %v", err) log.Printf("Error sorting gateways: %v", err)
return gws, err return gws, err
} else {
distance = tzDistance(tzOffsetHours, gwOffset)
} }
distance = tzDistance(tzOffsetHours, gwOffset)
gwVector = append(gwVector, gatewayDistance{gw, distance}) gwVector = append(gwVector, gatewayDistance{gw, distance})
} }
rand.Seed(time.Now().UnixNano()) rand.Seed(time.Now().UnixNano())
...@@ -262,7 +265,7 @@ func newGatewayPool(eip *eipService) *gatewayPool { ...@@ -262,7 +265,7 @@ func newGatewayPool(eip *eipService) *gatewayPool {
p := gatewayPool{} p := gatewayPool{}
p.available = eip.getGateways() p.available = eip.getGateways()
p.locations = eip.Locations p.locations = eip.Locations
p.byCity = make(map[string][]string, 0) p.byCity = make(map[string][]string)
p.populateCityList() p.populateCityList()
return &p return &p
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment