resp, err := http.Get("https://www.example.com") if err != nil { log.Fatal(err) } if resp.StatusCode == http.StatusOK { fmt.Println("HTTP request was successful") } else { fmt.Println("HTTP request failed") }
resp, err := http.Get("https://www.example.com/non-existent") if err != nil { log.Fatal(err) } if resp.StatusCode == http.StatusNotFound { fmt.Println("The requested resource was not found") } else { fmt.Println("HTTP request failed") }In this example, we make an HTTP GET request to `https://www.example.com/non-existent`. We then check if the response status code is equal to `http.StatusNotFound` (which is `404`). If it is, we print "The requested resource was not found". If it's not, we print "HTTP request failed". Package library: `net/http`