Defer closing

This commit is contained in:
Alexandre Bruyant 2024-01-06 22:17:31 +01:00
parent dad789954f
commit d93c7a6da7

11
main.go
View File

@ -70,6 +70,9 @@ func main() {
req.Header.Add("Content-Type", mwriter.FormDataContentType()) req.Header.Add("Content-Type", mwriter.FormDataContentType())
go func() { go func() {
defer mwriter.Close()
defer writer.Close()
err = filepath.Walk(path, func(innerPath string, info fs.FileInfo, err error) error { err = filepath.Walk(path, func(innerPath string, info fs.FileInfo, err error) error {
if err != nil { if err != nil {
return err return err
@ -103,14 +106,6 @@ func main() {
if err != nil { if err != nil {
githubactions.Fatalf("Unable to create request body: %v", fmt.Errorf("%w", err)) githubactions.Fatalf("Unable to create request body: %v", fmt.Errorf("%w", err))
} }
if err := mwriter.Close(); err != nil {
githubactions.Fatalf("Unable to close multipart writer: %v", fmt.Errorf("%w", err))
}
if err := writer.Close(); err != nil {
githubactions.Fatalf("Unable to close writer: %v", fmt.Errorf("%w", err))
}
}() }()
time.Sleep(10 * time.Second) time.Sleep(10 * time.Second)