MCPcopy Create free account
hub / github.com/auth0/auth0-cli / downloadFile

Function downloadFile

internal/cli/acul_app_scaffolding.go:507–531  ·  view source on GitHub ↗

downloadFile downloads a file from a URL to a temporary file and returns its name.

(url string)

Source from the content-addressed store, hash-verified

505
506// downloadFile downloads a file from a URL to a temporary file and returns its name.
507func downloadFile(url string) (string, error) {
508 client := &http.Client{Timeout: 15 * time.Second}
509
510 resp, err := client.Get(url)
511 if err != nil {
512 return "", fmt.Errorf("failed to download %s: %w", url, err)
513 }
514 defer resp.Body.Close()
515
516 if resp.StatusCode != http.StatusOK {
517 return "", fmt.Errorf("unexpected status code %d when downloading %s", resp.StatusCode, url)
518 }
519
520 tempFile, err := os.CreateTemp("", "github-zip-*.zip")
521 if err != nil {
522 return "", fmt.Errorf("failed to create temp file: %w", err)
523 }
524 defer tempFile.Close()
525
526 if _, err := io.Copy(tempFile, resp.Body); err != nil {
527 return "", fmt.Errorf("failed to save zip file: %w", err)
528 }
529
530 return tempFile.Name(), nil
531}
532
533// Function to copy a file from a source path to a destination path.
534func copyFile(src, dst string) error {

Callers 1

Calls 3

GetMethod · 0.80
ErrorfMethod · 0.80
CloseMethod · 0.80

Tested by

no test coverage detected