Skip to content

Commit

Permalink
updated code
Browse files Browse the repository at this point in the history
  • Loading branch information
vexsx committed Jan 11, 2024
1 parent 5272858 commit 1e10b6d
Showing 1 changed file with 16 additions and 3 deletions.
19 changes: 16 additions & 3 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,10 @@ prog:

fmt.Println("File saved successfully as", fileName)
fmt.Println("Press Enter to exit")
fmt.Scanln()
_, err = fmt.Scanln()
if err != nil {
return
}
}

func generateFileName() string {
Expand All @@ -80,7 +83,12 @@ func saveFile(url, fileName string) error {
if err != nil {
return err
}
defer response.Body.Close()
defer func(Body io.ReadCloser) {
err := Body.Close()
if err != nil {

}
}(response.Body)

if response.StatusCode != http.StatusOK {
return fmt.Errorf("unexpected status code: %d", response.StatusCode)
Expand All @@ -90,7 +98,12 @@ func saveFile(url, fileName string) error {
if err != nil {
return err
}
defer file.Close()
defer func(file *os.File) {
err := file.Close()
if err != nil {

}
}(file)

_, err = io.Copy(file, response.Body)
if err != nil {
Expand Down

0 comments on commit 1e10b6d

Please sign in to comment.