rename req to resp

Signed-off-by: mqliang <mqliang.zju@gmail.com>
This commit is contained in:
mqliang 2015-11-25 22:29:23 +08:00
parent 6bb27bcfda
commit b7d246effb

View file

@ -23,11 +23,11 @@ func Login(authConfig *cliconfig.AuthConfig, registryEndpoint *Endpoint) (string
// loginV1 tries to register/login to the v1 registry server. // loginV1 tries to register/login to the v1 registry server.
func loginV1(authConfig *cliconfig.AuthConfig, registryEndpoint *Endpoint) (string, error) { func loginV1(authConfig *cliconfig.AuthConfig, registryEndpoint *Endpoint) (string, error) {
var ( var (
status string status string
reqBody []byte respBody []byte
err error err error
reqStatusCode = 0 respStatusCode = 0
serverAddress = authConfig.ServerAddress serverAddress = authConfig.ServerAddress
) )
logrus.Debugf("attempting v1 login to registry endpoint %s", registryEndpoint) logrus.Debugf("attempting v1 login to registry endpoint %s", registryEndpoint)
@ -49,18 +49,18 @@ func loginV1(authConfig *cliconfig.AuthConfig, registryEndpoint *Endpoint) (stri
// using `bytes.NewReader(jsonBody)` here causes the server to respond with a 411 status. // using `bytes.NewReader(jsonBody)` here causes the server to respond with a 411 status.
b := strings.NewReader(string(jsonBody)) b := strings.NewReader(string(jsonBody))
req1, err := registryEndpoint.client.Post(serverAddress+"users/", "application/json; charset=utf-8", b) resp1, err := registryEndpoint.client.Post(serverAddress+"users/", "application/json; charset=utf-8", b)
if err != nil { if err != nil {
return "", fmt.Errorf("Server Error: %s", err) return "", fmt.Errorf("Server Error: %s", err)
} }
defer req1.Body.Close() defer resp1.Body.Close()
reqStatusCode = req1.StatusCode respStatusCode = resp1.StatusCode
reqBody, err = ioutil.ReadAll(req1.Body) respBody, err = ioutil.ReadAll(resp1.Body)
if err != nil { if err != nil {
return "", fmt.Errorf("Server Error: [%#v] %s", reqStatusCode, err) return "", fmt.Errorf("Server Error: [%#v] %s", respStatusCode, err)
} }
if reqStatusCode == 201 { if respStatusCode == 201 {
if loginAgainstOfficialIndex { if loginAgainstOfficialIndex {
status = "Account created. Please use the confirmation link we sent" + status = "Account created. Please use the confirmation link we sent" +
" to your e-mail to activate it." " to your e-mail to activate it."
@ -68,8 +68,8 @@ func loginV1(authConfig *cliconfig.AuthConfig, registryEndpoint *Endpoint) (stri
// *TODO: Use registry configuration to determine what this says, if anything? // *TODO: Use registry configuration to determine what this says, if anything?
status = "Account created. Please see the documentation of the registry " + serverAddress + " for instructions how to activate it." status = "Account created. Please see the documentation of the registry " + serverAddress + " for instructions how to activate it."
} }
} else if reqStatusCode == 400 { } else if respStatusCode == 400 {
if string(reqBody) == "\"Username or email already exists\"" { if string(respBody) == "\"Username or email already exists\"" {
req, err := http.NewRequest("GET", serverAddress+"users/", nil) req, err := http.NewRequest("GET", serverAddress+"users/", nil)
req.SetBasicAuth(authConfig.Username, authConfig.Password) req.SetBasicAuth(authConfig.Username, authConfig.Password)
resp, err := registryEndpoint.client.Do(req) resp, err := registryEndpoint.client.Do(req)
@ -97,9 +97,9 @@ func loginV1(authConfig *cliconfig.AuthConfig, registryEndpoint *Endpoint) (stri
} }
return "", fmt.Errorf("Login: %s (Code: %d; Headers: %s)", body, resp.StatusCode, resp.Header) return "", fmt.Errorf("Login: %s (Code: %d; Headers: %s)", body, resp.StatusCode, resp.Header)
} }
return "", fmt.Errorf("Registration: %s", reqBody) return "", fmt.Errorf("Registration: %s", respBody)
} else if reqStatusCode == 401 { } else if respStatusCode == 401 {
// This case would happen with private registries where /v1/users is // This case would happen with private registries where /v1/users is
// protected, so people can use `docker login` as an auth check. // protected, so people can use `docker login` as an auth check.
req, err := http.NewRequest("GET", serverAddress+"users/", nil) req, err := http.NewRequest("GET", serverAddress+"users/", nil)
@ -122,7 +122,7 @@ func loginV1(authConfig *cliconfig.AuthConfig, registryEndpoint *Endpoint) (stri
resp.StatusCode, resp.Header) resp.StatusCode, resp.Header)
} }
} else { } else {
return "", fmt.Errorf("Unexpected status code [%d] : %s", reqStatusCode, reqBody) return "", fmt.Errorf("Unexpected status code [%d] : %s", respStatusCode, respBody)
} }
return status, nil return status, nil
} }