logo
Free, Micro AI Code Reviews That Run on Git Commit
git-lrc git-lrc GitHub Install Now We'd appreciate a star git-lrc - Free, Micro AI Code Reviews That Run on Git Commit | Product Hunt git-lrc - Free, Micro AI Code Reviews That Run on Git Commit | Product Hunt

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