You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
funcmain() {
// Create a context with a timeoutctx, cancel:=context.WithTimeout(context.Background(), 5*time.Second)
defercancel()
// Create an HTTP client with the contextclient:=&http.Client{}
// Create a GET requestreq, err:=http.NewRequestWithContext(ctx, "GET", "https://example.com", nil)
iferr!=nil {
fmt.Println("Error creating request:", err)
return
}
// Perform the requestresponse, err:=client.Do(req)
iferr!=nil {
// Check if the error is due to a timeoutifctx.Err() ==context.DeadlineExceeded {
fmt.Println("Request timed out")
return
}
// Handle other errorsfmt.Println("Error performing request:", err)
return
}
deferresponse.Body.Close()
No description provided.
The text was updated successfully, but these errors were encountered: