1
0
Fork 0
mirror of https://github.com/moby/moby.git synced 2022-11-09 12:21:53 -05:00

cleaned up the code a little

This commit is contained in:
Ken Cochrane 2013-03-14 18:43:02 -07:00
parent 18519f12ae
commit f1cf5074f5

View file

@ -92,14 +92,14 @@ func Login(authConfig AuthConfig) (string, error) {
jsonBody, _ := json.Marshal(authConfig) jsonBody, _ := json.Marshal(authConfig)
b := strings.NewReader(string(jsonBody)) b := strings.NewReader(string(jsonBody))
req1, err := http.Post(REGISTRY_SERVER+"/v1/users", "application/json; charset=utf-8", b) req1, err := http.Post(REGISTRY_SERVER+"/v1/users", "application/json; charset=utf-8", b)
if err == nil { if err != nil {
body, _ := ioutil.ReadAll(req1.Body)
reqStatusCode = req1.StatusCode
reqBody = body
req1.Body.Close()
} else {
return "", err return "", err
} }
reqBody, _ = ioutil.ReadAll(req1.Body)
reqStatusCode = req1.StatusCode
req1.Body.Close()
if reqStatusCode == 201 { if reqStatusCode == 201 {
status = "Account Created\n" status = "Account Created\n"
storeConfig = true storeConfig = true
@ -121,12 +121,16 @@ func Login(authConfig AuthConfig) (string, error) {
status = "Login Succeeded\n" status = "Login Succeeded\n"
storeConfig = true storeConfig = true
} else { } else {
storeConfig = false status = fmt.Sprintf("Login Error: %s\n", body)
status = fmt.Sprintf("Error: %s\n", body) return "", errors.New(status)
} }
} else { } else {
status = fmt.Sprintf("Error: %s\n", reqBody) status = fmt.Sprintf("Registration Error: %s\n", reqBody)
return "", errors.New(status)
} }
} else {
status = fmt.Sprintf("Error: %s : %s \n", reqStatusCode, reqBody)
return "", errors.New(status)
} }
if storeConfig { if storeConfig {
authStr := EncodeAuth(authConfig) authStr := EncodeAuth(authConfig)