Skip to content

Instantly share code, notes, and snippets.

@dmitris
Created May 26, 2023 09:37
Show Gist options
  • Save dmitris/8d5ee918e2577e7d5eedc28830a6ede1 to your computer and use it in GitHub Desktop.
Save dmitris/8d5ee918e2577e7d5eedc28830a6ede1 to your computer and use it in GitHub Desktop.
Go test program fetching https://example.com URL
package main
import (
"fmt"
"io"
"log"
"net/http"
)
const link = "https://example.com"
func main() {
resp, err := http.Get(link)
if err != nil {
log.Fatal(err)
}
defer resp.Body.Close()
body, err := io.ReadAll(resp.Body)
if err != nil {
log.Fatal(err)
}
fmt.Println(string(body))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment