fetchURL downloads the content at the given URL with a short timeout.
(url string)
| 184 | |
| 185 | // fetchURL downloads the content at the given URL with a short timeout. |
| 186 | func fetchURL(url string) ([]byte, error) { |
| 187 | client := &http.Client{Timeout: 20 * time.Second} |
| 188 | resp, err := client.Get(url) //nolint:gosec // URL is user-provided CLI flag |
| 189 | if err != nil { |
| 190 | return nil, err |
| 191 | } |
| 192 | defer func() { |
| 193 | _ = resp.Body.Close() |
| 194 | }() |
| 195 | if resp.StatusCode != http.StatusOK { |
| 196 | return nil, fmt.Errorf("unexpected status: %s", resp.Status) |
| 197 | } |
| 198 | return io.ReadAll(resp.Body) |
| 199 | } |
| 200 | |
| 201 | // writeJSON writes data to a path with secure permissions. |
| 202 | func writeJSON(path string, data interface{}) error { |