Go HTTP GET Request Example
This example demonstrates a simple HTTP GET request in Go.
package main
import (
"fmt"
"net/http"
)
func main() {
url := "https://ruan.dev"
resp, err := http.Get(url)
if err != nil {
fmt.Println("Error while fetching the URL:", err)
return
}
defer resp.Body.Close()
fmt.Println(resp.StatusCode)
}
This code fetches the URL and prints the status code. Error handling is included to manage potential issues during the request.
Further Reading
For more information on making HTTP requests in Go, refer to the official documentation: