Skip to content

Instantly share code, notes, and snippets.

@rsperl
Last active July 25, 2022 16:05
Show Gist options
  • Save rsperl/1ab8b17fb0fb1eff1369511f026e9c15 to your computer and use it in GitHub Desktop.
Save rsperl/1ab8b17fb0fb1eff1369511f026e9c15 to your computer and use it in GitHub Desktop.
download binary file #go #snippet
import (
"encoding/binary"
"fmt"
"io/ioutil"
"net/http"
"os"
)
func download() string {
client := &http.Client{}
req, err := http.NewRequest("GET", downloadURL, nil)
resp, err := client.Do(req)
if err != nil {
fmt.Printf("error downloading new version: %v\n", err)
os.Exit(1)
}
respBody, _ := ioutil.ReadAll(resp.Body)
defer resp.Body.Close()
filename := tmpdir + "/calibre.img"
fh, _ := os.Create(filename)
err = binary.Write(fh, binary.LittleEndian, respBody)
return filename
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment