Un-nest switch in gateway update handler

This commit is contained in:
freddygv 2020-04-14 16:50:03 -06:00
parent 7d5a02ad61
commit b2b5942f4b

View file

@ -891,8 +891,8 @@ func (s *state) handleUpdateTerminatingGateway(u cache.UpdateEvent, snap *Config
} }
logger := s.logger.Named(logging.TerminatingGateway) logger := s.logger.Named(logging.TerminatingGateway)
switch u.CorrelationID { switch {
case rootsWatchID: case u.CorrelationID == rootsWatchID:
roots, ok := u.Result.(*structs.IndexedCARoots) roots, ok := u.Result.(*structs.IndexedCARoots)
if !ok { if !ok {
return fmt.Errorf("invalid type for response: %T", u.Result) return fmt.Errorf("invalid type for response: %T", u.Result)
@ -900,7 +900,7 @@ func (s *state) handleUpdateTerminatingGateway(u cache.UpdateEvent, snap *Config
snap.Roots = roots snap.Roots = roots
// Update watches based on the current list of services associated with the terminating-gateway // Update watches based on the current list of services associated with the terminating-gateway
case gatewayServicesWatchID: case u.CorrelationID == gatewayServicesWatchID:
services, ok := u.Result.(*structs.IndexedGatewayServices) services, ok := u.Result.(*structs.IndexedGatewayServices)
if !ok { if !ok {
return fmt.Errorf("invalid type for response: %T", u.Result) return fmt.Errorf("invalid type for response: %T", u.Result)
@ -1052,9 +1052,6 @@ func (s *state) handleUpdateTerminatingGateway(u cache.UpdateEvent, snap *Config
} }
} }
default:
switch {
// Store service instances for watched service
case strings.HasPrefix(u.CorrelationID, "external-service:"): case strings.HasPrefix(u.CorrelationID, "external-service:"):
resp, ok := u.Result.(*structs.IndexedCheckServiceNodes) resp, ok := u.Result.(*structs.IndexedCheckServiceNodes)
if !ok { if !ok {
@ -1097,7 +1094,6 @@ func (s *state) handleUpdateTerminatingGateway(u cache.UpdateEvent, snap *Config
default: default:
// do nothing // do nothing
} }
}
return nil return nil
} }