/
spirzen
/
it-code-examples
Обзор
Документация
Войти
/
spirzen
/
it-code-examples
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
master
examples/go/http-get/main.go
24 строки
476 B
Spirzen
Init
07 июн 2026, 02:39
07 июн 2026, 02:39
ca7a590
Код
Авторство
О чём код?
package main import ( "context" "fmt" "io" "net/http" "time" ) func main() { ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second) defer cancel() req, _ := http.NewRequestWithContext(ctx, http.MethodGet, "https://httpbin.org/get", nil) res, err := http.DefaultClient.Do(req) if err != nil { panic(err) } defer res.Body.Close() body, _ := io.ReadAll(io.LimitReader(res.Body, 256)) fmt.Printf("status=%d body=%q\n", res.StatusCode, body) }