package main
import (
"fmt"
"io"
"net/http"
"os"
)
func main() {
url := "https://example.com/minecraft_logo.png"
outputFile := "minecraft_logo.png"
err := downloadFile(url, outputFile)
if err != nil {
fmt.Println("Error downloading file:", err)
return
}
fmt.Println("Downloaded:", outputFile)
}
func downloadFile(url string, outputFile string) error {
response, err := http.Get(url)
if err != nil {
return err
}
defer response.Body.Close()
file, err := os.Create(outputFile)
if err != nil {
return err
}
defer file.Close()
_, err = io.Copy(file, response.Body)
if err != nil {
return err
}
return nil
}