Исходники и презентации
This commit is contained in:
22
lessons/contexts/context_with_http_client/main.go
Normal file
22
lessons/contexts/context_with_http_client/main.go
Normal file
@ -0,0 +1,22 @@
|
||||
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())
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user