From 1e10b6d668ac671f8d1aee7d562efe3397fe2d3d Mon Sep 17 00:00:00 2001 From: vexsx Date: Thu, 11 Jan 2024 21:00:18 +0330 Subject: [PATCH] updated code --- main.go | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/main.go b/main.go index 5592044..39fc8e6 100644 --- a/main.go +++ b/main.go @@ -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 { @@ -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) @@ -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 {