Last active
January 27, 2023 15:29
-
-
Save orian/b54ce2b1cc3a4144b090eb5714725a43 to your computer and use it in GitHub Desktop.
golang send a http request with a context deadline exceeded
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"context" | |
"net/http" | |
) | |
func checkErr(err error) { | |
if err != nil { | |
panic(err) | |
} | |
} | |
func main() { | |
ctx, _ := context.WithTimeout(context.Background(), 0) | |
r, err := http.NewRequestWithContext(ctx, http.MethodGet, "https://www.google.pl", nil) | |
checkErr(err) | |
_, err = http.DefaultClient.Do(r) | |
// panic: Get "https://www.google.pl": context deadline exceeded | |
checkErr(err) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment