Risk-Aware Code Review: Auto Approve Low-Risk Changes
LiveReview LiveReview LiveReview - Free, Risk-Aware Code Review: Auto Approve Low-Risk Changes | Product Hunt LiveReview - Free, Risk-Aware Code Review: Auto Approve Low-Risk Changes | Product Hunt GitHub Install Now

We'd appreciate a star

Go HTTP GET Request Example - Fetch and Display Status Code

Learn how to make an HTTP GET request in Go and display the status code. This simple example demonstrates fetching a URL and handling potential errors.

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:

See Also