Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save jeffotoni/c6e8027205e0ef3c28bd746240314fc1 to your computer and use it in GitHub Desktop.
Save jeffotoni/c6e8027205e0ef3c28bd746240314fc1 to your computer and use it in GitHub Desktop.
package main
import (
"context"
"fmt"
"log"
"net/http"
"time"
)
func main() {
req, err := http.NewRequest("GET", "https://golang.org/help", nil)
if err != nil {
log.Fatalf("%v", err)
}
ctx, cancel := context.WithTimeout(req.Context(), 1*time.Millisecond)
defer cancel()
req = req.WithContext(ctx)
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