Files
deep_go/lessons/contexts/context_with_http_client/main.go

23 lines
397 B
Go

package main
import (
"context"
"fmt"
"net/http"
"time"
)
func main() {
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Millisecond)
defer cancel()
req, err := http.NewRequestWithContext(ctx, http.MethodGet, "https://example.com", nil)
if err != nil {
fmt.Println(err.Error())
}
if _, err = http.DefaultClient.Do(req); err != nil {
fmt.Println(err.Error())
}
}