فهرست منبع

Merge pull request #12521 from runcom/else-nit

Refactor else branches
Brian Goff 10 سال پیش
والد
کامیت
24b89b7098
1فایلهای تغییر یافته به همراه11 افزوده شده و 13 حذف شده
  1. 11 13
      registry/session.go

+ 11 - 13
registry/session.go

@@ -222,10 +222,10 @@ func (r *Session) GetRemoteTags(registries []string, repository string, token []
 		logrus.Debugf("Got status code %d from %s", res.StatusCode, endpoint)
 		logrus.Debugf("Got status code %d from %s", res.StatusCode, endpoint)
 		defer res.Body.Close()
 		defer res.Body.Close()
 
 
-		if res.StatusCode != 200 && res.StatusCode != 404 {
-			continue
-		} else if res.StatusCode == 404 {
+		if res.StatusCode == 404 {
 			return nil, fmt.Errorf("Repository not found")
 			return nil, fmt.Errorf("Repository not found")
+		} else if res.StatusCode != 200 {
+			continue
 		}
 		}
 
 
 		result := make(map[string]string)
 		result := make(map[string]string)
@@ -524,21 +524,19 @@ func (r *Session) PushImageJSONIndex(remote string, imgList []*ImgData, validate
 			}
 			}
 			return nil, httputils.NewHTTPRequestError(fmt.Sprintf("Error: Status %d trying to push repository %s: %q", res.StatusCode, remote, errBody), res)
 			return nil, httputils.NewHTTPRequestError(fmt.Sprintf("Error: Status %d trying to push repository %s: %q", res.StatusCode, remote, errBody), res)
 		}
 		}
-		if res.Header.Get("X-Docker-Token") != "" {
-			tokens = res.Header["X-Docker-Token"]
-			logrus.Debugf("Auth token: %v", tokens)
-		} else {
+		if res.Header.Get("X-Docker-Token") == "" {
 			return nil, fmt.Errorf("Index response didn't contain an access token")
 			return nil, fmt.Errorf("Index response didn't contain an access token")
 		}
 		}
+		tokens = res.Header["X-Docker-Token"]
+		logrus.Debugf("Auth token: %v", tokens)
 
 
-		if res.Header.Get("X-Docker-Endpoints") != "" {
-			endpoints, err = buildEndpointsList(res.Header["X-Docker-Endpoints"], r.indexEndpoint.VersionString(1))
-			if err != nil {
-				return nil, err
-			}
-		} else {
+		if res.Header.Get("X-Docker-Endpoints") == "" {
 			return nil, fmt.Errorf("Index response didn't contain any endpoints")
 			return nil, fmt.Errorf("Index response didn't contain any endpoints")
 		}
 		}
+		endpoints, err = buildEndpointsList(res.Header["X-Docker-Endpoints"], r.indexEndpoint.VersionString(1))
+		if err != nil {
+			return nil, err
+		}
 	}
 	}
 	if validate {
 	if validate {
 		if res.StatusCode != 204 {
 		if res.StatusCode != 204 {