Skip to content

Commit

Permalink
Fixed for in loop
Browse files Browse the repository at this point in the history
  • Loading branch information
m1ome committed Dec 25, 2017
1 parent 25672b8 commit 1175eaf
Showing 1 changed file with 18 additions and 11 deletions.
29 changes: 18 additions & 11 deletions api.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,20 +49,27 @@ func (b *Bot) sendFiles(
writer := multipart.NewWriter(body)

for name, path := range files {
file, err := os.Open(path)
if err != nil {
if err := func() error {
file, err := os.Open(path)
if err != nil {
return err
}
defer file.Close()

part, err := writer.CreateFormFile(name, filepath.Base(path))
if err != nil {
return err
}

if _, err = io.Copy(part, file); err != nil {
return err
}

return nil
} (); err != nil {
return nil, wrapSystem(err)
}
defer file.Close()

part, err := writer.CreateFormFile(name, filepath.Base(path))
if err != nil {
return nil, wrapSystem(err)
}

if _, err = io.Copy(part, file); err != nil {
return nil, wrapSystem(err)
}
}

for field, value := range params {
Expand Down

0 comments on commit 1175eaf

Please sign in to comment.