Skip to content

Commit e8ffcc8

Browse files
committed
fix(lint): refactor error handling in SetFileFromPath function
- Replace calls to log.Fatal with return statements in the SetFileFromPath function to prevent program termination on error. Signed-off-by: appleboy <[email protected]>
1 parent fd19340 commit e8ffcc8

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

gofight.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -223,26 +223,26 @@ func (rc *RequestConfig) SetFileFromPath(uploads []UploadFile, params ...H) *Req
223223
if reader.Size() == 0 {
224224
file, err := os.Open(f.Path)
225225
if err != nil {
226-
log.Fatal(err)
226+
return rc
227227
}
228228

229229
defer file.Close()
230230
part, err := writer.CreateFormFile(f.Name, filepath.Base(f.Path))
231231
if err != nil {
232-
log.Fatal(err)
232+
return rc
233233
}
234234
_, err = io.Copy(part, file)
235235
if err != nil {
236-
log.Fatal(err)
236+
return rc
237237
}
238238
} else {
239239
part, err := writer.CreateFormFile(f.Name, filepath.Base(f.Path))
240240
if err != nil {
241-
log.Fatal(err)
241+
return rc
242242
}
243243
_, err = reader.WriteTo(part)
244244
if err != nil {
245-
log.Fatal(err)
245+
return rc
246246
}
247247
}
248248
}
@@ -255,7 +255,7 @@ func (rc *RequestConfig) SetFileFromPath(uploads []UploadFile, params ...H) *Req
255255

256256
err := writer.Close()
257257
if err != nil {
258-
log.Fatal(err)
258+
return rc
259259
}
260260

261261
rc.ContentType = writer.FormDataContentType()

0 commit comments

Comments
 (0)