downloadFile downloads a URL to a local file path.
(filepath string, url string)
| 266 | |
| 267 | // downloadFile downloads a URL to a local file path. |
| 268 | func downloadFile(filepath string, url string) error { |
| 269 | resp, err := http.Get(url) |
| 270 | if err != nil { |
| 271 | return err |
| 272 | } |
| 273 | defer resp.Body.Close() |
| 274 | |
| 275 | if resp.StatusCode != http.StatusOK { |
| 276 | return fmt.Errorf("HTTP %d: %s", resp.StatusCode, resp.Status) |
| 277 | } |
| 278 | |
| 279 | out, err := os.Create(filepath) |
| 280 | if err != nil { |
| 281 | return err |
| 282 | } |
| 283 | defer out.Close() |
| 284 | |
| 285 | _, err = io.Copy(out, resp.Body) |
| 286 | return err |
| 287 | } |
| 288 | |
| 289 | // sha256File computes the SHA256 hash of a file and returns the hex string. |
| 290 | func sha256File(path string) (string, error) { |
no test coverage detected