mirror of
https://github.com/go-micro/go-micro.git
synced 2024-11-24 08:02:32 +02:00
Changed names of some variables.
This commit is contained in:
parent
d5ce96da24
commit
7a4bff4e9f
@ -682,7 +682,7 @@ func (r *router) flushRouteEvents(evType EventType) ([]*Event, error) {
|
|||||||
return nil, fmt.Errorf("failed listing routes: %s", err)
|
return nil, fmt.Errorf("failed listing routes: %s", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if r.options.Advertise == All {
|
if r.options.Advertise == AdvertiseAll {
|
||||||
// build a list of events to advertise
|
// build a list of events to advertise
|
||||||
events := make([]*Event, len(routes))
|
events := make([]*Event, len(routes))
|
||||||
for i, route := range routes {
|
for i, route := range routes {
|
||||||
@ -697,33 +697,36 @@ func (r *router) flushRouteEvents(evType EventType) ([]*Event, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// routeMap stores optimal routes per service
|
// routeMap stores optimal routes per service
|
||||||
optimalRoutes := make(map[string]Route)
|
bestRoutes := make(map[string]Route)
|
||||||
|
|
||||||
// go through all routes found in the routing table and collapse them to optimal routes
|
// go through all routes found in the routing table and collapse them to optimal routes
|
||||||
for _, route := range routes {
|
for _, route := range routes {
|
||||||
optimal, ok := optimalRoutes[route.Service]
|
routeKey := route.Service + "@" + route.Network
|
||||||
|
optimal, ok := bestRoutes[routeKey]
|
||||||
if !ok {
|
if !ok {
|
||||||
optimalRoutes[route.Service] = route
|
bestRoutes[routeKey] = route
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
// if the current optimal route metric is higher than routing table route, replace it
|
// if the current optimal route metric is higher than routing table route, replace it
|
||||||
if optimal.Metric > route.Metric {
|
if optimal.Metric > route.Metric {
|
||||||
optimalRoutes[route.Service] = route
|
bestRoutes[routeKey] = route
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
// if the metrics are the same, prefer advertising your own route
|
// if the metrics are the same, prefer advertising your own route
|
||||||
if optimal.Metric == route.Metric {
|
if optimal.Metric == route.Metric {
|
||||||
if route.Router == r.options.Id {
|
if route.Router == r.options.Id {
|
||||||
optimalRoutes[route.Service] = route
|
bestRoutes[routeKey] = route
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
log.Debugf("Router advertising %d best routes out of %d", len(bestRoutes), len(routes))
|
||||||
|
|
||||||
// build a list of events to advertise
|
// build a list of events to advertise
|
||||||
events := make([]*Event, len(optimalRoutes))
|
events := make([]*Event, len(bestRoutes))
|
||||||
i := 0
|
i := 0
|
||||||
for _, route := range optimalRoutes {
|
for _, route := range bestRoutes {
|
||||||
event := &Event{
|
event := &Event{
|
||||||
Type: evType,
|
Type: evType,
|
||||||
Timestamp: time.Now(),
|
Timestamp: time.Now(),
|
||||||
|
@ -80,6 +80,6 @@ func DefaultOptions() Options {
|
|||||||
Address: DefaultAddress,
|
Address: DefaultAddress,
|
||||||
Network: DefaultNetwork,
|
Network: DefaultNetwork,
|
||||||
Registry: registry.DefaultRegistry,
|
Registry: registry.DefaultRegistry,
|
||||||
Advertise: Optimal,
|
Advertise: AdvertiseBest,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -143,19 +143,19 @@ type Advert struct {
|
|||||||
type Strategy int
|
type Strategy int
|
||||||
|
|
||||||
const (
|
const (
|
||||||
// All advertises all routes to the network
|
// AdvertiseAll advertises all routes to the network
|
||||||
All Strategy = iota
|
AdvertiseAll Strategy = iota
|
||||||
// Optimal advertises optimal routes to the network
|
// AdvertiseBest advertises optimal routes to the network
|
||||||
Optimal
|
AdvertiseBest
|
||||||
)
|
)
|
||||||
|
|
||||||
// String returns human readable Strategy
|
// String returns human readable Strategy
|
||||||
func (s Strategy) String() string {
|
func (s Strategy) String() string {
|
||||||
switch s {
|
switch s {
|
||||||
case All:
|
case AdvertiseAll:
|
||||||
return "all"
|
return "all"
|
||||||
case Optimal:
|
case AdvertiseBest:
|
||||||
return "optimal"
|
return "best"
|
||||||
default:
|
default:
|
||||||
return "unknown"
|
return "unknown"
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user