Skip to content
Branch: master
Find file Copy path
Find file Copy path
init 06b9897 Jun 19, 2018
1 contributor

Users who have contributed to this file

31 lines (27 sloc) 782 Bytes
package main
import (
func main() {
// Create a new context
// With a deadline of 100 milliseconds
ctx := context.Background()
ctx, _ = context.WithTimeout(ctx, 100*time.Millisecond)
// Make a request, that will call the google homepage
req, _ := http.NewRequest(http.MethodGet, "", nil)
// Associate the cancellable context we just created to the request
req = req.WithContext(ctx)
// Create a new HTTP client and execute the request
client := &http.Client{}
res, err := client.Do(req)
// If the request failed, log to STDOUT
if err != nil {
fmt.Println("Request failed:", err)
// Print the statuscode if the request succeeds
fmt.Println("Response received, status code:", res.StatusCode)
You can’t perform that action at this time.