From baf216e1675df21daf66e4b9e904e13116f09a35 Mon Sep 17 00:00:00 2001 From: Bo-Yi Wu Date: Tue, 4 Jul 2017 03:12:29 -0500 Subject: [PATCH] add error check. (#972) Signed-off-by: Bo-Yi Wu --- examples/upload-file/multiple/main.go | 18 +++++++++++++++--- examples/upload-file/single/main.go | 18 +++++++++++++++--- 2 files changed, 30 insertions(+), 6 deletions(-) diff --git a/examples/upload-file/multiple/main.go b/examples/upload-file/multiple/main.go index 2f4e9b52..22588348 100644 --- a/examples/upload-file/multiple/main.go +++ b/examples/upload-file/multiple/main.go @@ -17,16 +17,28 @@ func main() { email := c.PostForm("email") // Multipart form - form, _ := c.MultipartForm() + form, err := c.MultipartForm() + if err != nil { + c.String(http.StatusBadRequest, fmt.Sprintf("get form err: %s", err.Error())) + return + } files := form.File["files"] for _, file := range files { // Source - src, _ := file.Open() + src, err := file.Open() + if err != nil { + c.String(http.StatusBadRequest, fmt.Sprintf("file open err: %s", err.Error())) + return + } defer src.Close() // Destination - dst, _ := os.Create(file.Filename) + dst, err := os.Create(file.Filename) + if err != nil { + c.String(http.StatusBadRequest, fmt.Sprintf("Create file err: %s", err.Error())) + return + } defer dst.Close() // Copy diff --git a/examples/upload-file/single/main.go b/examples/upload-file/single/main.go index 9acf5009..1e9596cb 100644 --- a/examples/upload-file/single/main.go +++ b/examples/upload-file/single/main.go @@ -17,12 +17,24 @@ func main() { email := c.PostForm("email") // Source - file, _ := c.FormFile("file") - src, _ := file.Open() + file, err := c.FormFile("file") + if err != nil { + c.String(http.StatusBadRequest, fmt.Sprintf("get form err: %s", err.Error())) + return + } + src, err := file.Open() + if err != nil { + c.String(http.StatusBadRequest, fmt.Sprintf("file open err: %s", err.Error())) + return + } defer src.Close() // Destination - dst, _ := os.Create(file.Filename) + dst, err := os.Create(file.Filename) + if err != nil { + c.String(http.StatusBadRequest, fmt.Sprintf("Create file err: %s", err.Error())) + return + } defer dst.Close() // Copy