Created
December 28, 2019 00:30
-
-
Save Clivern/d05ae73065a3da79891b21c3f23647ee to your computer and use it in GitHub Desktop.
This file contains hidden or 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" | |
| "fmt" | |
| "log" | |
| "net/http" | |
| "time" | |
| ) | |
| func main() { | |
| ctx, cancel := context.WithTimeout(context.Background(), 1000*time.Millisecond) | |
| defer cancel() | |
| req, err := http.NewRequestWithContext(ctx, "GET", "https://httpbin.org/get", nil) | |
| if err != nil { | |
| log.Fatalf("%v", err) | |
| } | |
| client := http.DefaultClient | |
| res, err := client.Do(req) | |
| if err != nil { | |
| log.Fatalf("%v", err) | |
| } | |
| fmt.Printf("%v\n", res.StatusCode) | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment