func makeRequest() error {
req, err := http.NewRequest(http.MethodGet, "https://habr.com", nil)
if err != nil {
return err
}
req.Header.Add("User-Agent", "mySuperTestApp v1.0")
res, err := http.DefaultClient.Do(req)
if err != nil {
return err
}
defer res.Body.Close()
if res.StatusCode != http.StatusOK {
return fmt.Errorf("wrong status code: %d", res.StatusCode)
}
body, err := io.ReadAll(res.Body)
if err != nil {
return err
}
fmt.Println(string(body))
return nil
}