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)
|
||||
}
|
||||
|
||||
if r.options.Advertise == All {
|
||||
if r.options.Advertise == AdvertiseAll {
|
||||
// build a list of events to advertise
|
||||
events := make([]*Event, len(routes))
|
||||
for i, route := range routes {
|
||||
@ -697,33 +697,36 @@ func (r *router) flushRouteEvents(evType EventType) ([]*Event, error) {
|
||||
}
|
||||
|
||||
// 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
|
||||
for _, route := range routes {
|
||||
optimal, ok := optimalRoutes[route.Service]
|
||||
routeKey := route.Service + "@" + route.Network
|
||||
optimal, ok := bestRoutes[routeKey]
|
||||
if !ok {
|
||||
optimalRoutes[route.Service] = route
|
||||
bestRoutes[routeKey] = route
|
||||
continue
|
||||
}
|
||||
// if the current optimal route metric is higher than routing table route, replace it
|
||||
if optimal.Metric > route.Metric {
|
||||
optimalRoutes[route.Service] = route
|
||||
bestRoutes[routeKey] = route
|
||||
continue
|
||||
}
|
||||
// if the metrics are the same, prefer advertising your own route
|
||||
if optimal.Metric == route.Metric {
|
||||
if route.Router == r.options.Id {
|
||||
optimalRoutes[route.Service] = route
|
||||
bestRoutes[routeKey] = route
|
||||
continue
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
log.Debugf("Router advertising %d best routes out of %d", len(bestRoutes), len(routes))
|
||||
|
||||
// build a list of events to advertise
|
||||
events := make([]*Event, len(optimalRoutes))
|
||||
events := make([]*Event, len(bestRoutes))
|
||||
i := 0
|
||||
for _, route := range optimalRoutes {
|
||||
for _, route := range bestRoutes {
|
||||
event := &Event{
|
||||
Type: evType,
|
||||
Timestamp: time.Now(),
|
||||
|
@ -80,6 +80,6 @@ func DefaultOptions() Options {
|
||||
Address: DefaultAddress,
|
||||
Network: DefaultNetwork,
|
||||
Registry: registry.DefaultRegistry,
|
||||
Advertise: Optimal,
|
||||
Advertise: AdvertiseBest,
|
||||
}
|
||||
}
|
||||
|
@ -143,19 +143,19 @@ type Advert struct {
|
||||
type Strategy int
|
||||
|
||||
const (
|
||||
// All advertises all routes to the network
|
||||
All Strategy = iota
|
||||
// Optimal advertises optimal routes to the network
|
||||
Optimal
|
||||
// AdvertiseAll advertises all routes to the network
|
||||
AdvertiseAll Strategy = iota
|
||||
// AdvertiseBest advertises optimal routes to the network
|
||||
AdvertiseBest
|
||||
)
|
||||
|
||||
// String returns human readable Strategy
|
||||
func (s Strategy) String() string {
|
||||
switch s {
|
||||
case All:
|
||||
case AdvertiseAll:
|
||||
return "all"
|
||||
case Optimal:
|
||||
return "optimal"
|
||||
case AdvertiseBest:
|
||||
return "best"
|
||||
default:
|
||||
return "unknown"
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user