add error check. (#972)

Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
This commit is contained in:
Bo-Yi Wu 2017-07-04 03:12:29 -05:00 committed by GitHub
parent df67c64479
commit baf216e167
2 changed files with 30 additions and 6 deletions

View File

@ -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

View File

@ -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