MCPcopy Create free account
hub / github.com/devnullvoid/pvetui / fetchURL

Function fetchURL

cmd/pve-openapi-gen/main.go:186–199  ·  view source on GitHub ↗

fetchURL downloads the content at the given URL with a short timeout.

(url string)

Source from the content-addressed store, hash-verified

184
185// fetchURL downloads the content at the given URL with a short timeout.
186func 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.
202func writeJSON(path string, data interface{}) error {

Callers 1

runFunction · 0.85

Calls 2

GetMethod · 0.95
CloseMethod · 0.65

Tested by

no test coverage detected