golang http save downloaded file

package main

import (
    "fmt"
    "io"
    "net/http"
    "os"
)

func main() {
    // URL of the file to be downloaded
    fileURL := "https://example.com/file-to-download.txt"

    // Create a GET request to the specified URL
    resp, err := http.Get(fileURL)
    if err != nil {
        fmt.Println("Error downloading file:", err)
        return
    }
    defer resp.Body.Close()

    // Create a new file to save the downloaded content
    out, err := os.Create("downloaded-file.txt")
    if err != nil {
        fmt.Println("Error creating file:", err)
        return
    }
    defer out.Close()

    // Copy the content from the HTTP response body to the local file
    _, err = io.Copy(out, resp.Body)
    if err != nil {
        fmt.Println("Error copying content to file:", err)
        return
    }

    fmt.Println("File downloaded successfully.")
}