Use early return pattern to avoid nested conditions

Signed-off-by: jongwooo <jongwooo.han@gmail.com>
This commit is contained in:
Jongwoo Han 2023-05-03 02:27:26 +09:00 committed by GitHub
parent 2e78e07ee5
commit e51e5962d5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -140,14 +140,14 @@ func (s *sourceFile) consumeWatchEvent(e *watchEvent) error {
pod, podExist, err := s.store.GetByKey(objKey)
if err != nil {
return err
} else if !podExist {
return fmt.Errorf("the pod with key %s doesn't exist in cache", objKey)
} else {
if err = s.store.Delete(pod); err != nil {
return fmt.Errorf("failed to remove deleted pod from cache: %v", err)
}
delete(s.fileKeyMapping, e.fileName)
}
if !podExist {
return fmt.Errorf("the pod with key %s doesn't exist in cache", objKey)
}
if err = s.store.Delete(pod); err != nil {
return fmt.Errorf("failed to remove deleted pod from cache: %v", err)
}
delete(s.fileKeyMapping, e.fileName)
}
}
return nil