Download downloads a file from the specified URL
(url string)
| 11 | |
| 12 | // Download downloads a file from the specified URL |
| 13 | func download(url string) ([]byte, error) { |
| 14 | response, err := http.Get(url) |
| 15 | if err != nil { |
| 16 | return nil, err |
| 17 | } |
| 18 | defer response.Body.Close() |
| 19 | |
| 20 | if response.StatusCode != http.StatusOK { |
| 21 | return nil, fmt.Errorf("failed to download file: %s", response.Status) |
| 22 | } |
| 23 | |
| 24 | data, err := io.ReadAll(response.Body) |
| 25 | if err != nil { |
| 26 | return nil, err |
| 27 | } |
| 28 | |
| 29 | return data, nil |
| 30 | } |