Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 14 additions & 8 deletions ch11/rClient.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,11 @@ func deleteEndpoint(server string, user User) int {
if err != nil {
fmt.Println("Error:", err)
}
defer resp.Body.Close()

if resp == nil {
return http.StatusBadRequest
}
defer resp.Body.Close()

data, err := io.ReadAll(resp.Body)
fmt.Print("/delete returned: ", string(data))
Expand Down Expand Up @@ -80,12 +80,13 @@ func getEndpoint(server string, user User) int {
resp, err := c.Do(req)
if err != nil {
fmt.Println("Error:", err)
return http.StatusBadGateway
}
defer resp.Body.Close()

if resp == nil {
return resp.StatusCode
return http.StatusBadGateway
}
defer resp.Body.Close()

data, err := io.ReadAll(resp.Body)
fmt.Print("/get returned: ", string(data))
Expand Down Expand Up @@ -116,11 +117,15 @@ func addEndpoint(server string, user User) int {
}

resp, err := c.Do(req)
if resp == nil || (resp.StatusCode == http.StatusNotFound) {
return resp.StatusCode
if err != nil {
fmt.Println("do:", err)
return http.StatusBadGateway
}
defer resp.Body.Close()

if resp.StatusCode == http.StatusNotFound {
return http.StatusNotFound
}
return resp.StatusCode
}

Expand All @@ -136,8 +141,9 @@ func timeEndpoint(server string) (int, string) {
}

resp, err := c.Do(req)
if resp == nil || (resp.StatusCode == http.StatusNotFound) {
return resp.StatusCode, ""
if err != nil {
fmt.Println("do:", err)
return http.StatusBadGateway, ""
}
defer resp.Body.Close()

Expand All @@ -158,7 +164,7 @@ func slashEndpoint(server, URL string) (int, string) {

resp, err := c.Do(req)
if resp == nil {
return resp.StatusCode, ""
return http.StatusBadGateway, ""
}
defer resp.Body.Close()

Expand Down