Skip to content

Commit 7ece236

Browse files
committedApr 2, 2025·
feat: use defer processing error
1 parent 051cda5 commit 7ece236

File tree

2 files changed

+2
-4
lines changed

2 files changed

+2
-4
lines changed
 

‎client/sse.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -399,7 +399,7 @@ func (c *SSEMCPClient) Initialize(
399399
err,
400400
)
401401
}
402-
resp.Body.Close()
402+
defer resp.Body.Close()
403403

404404
c.initialized = true
405405
return &result, nil

‎server/internal/gen/main.go

+1-3
Original file line numberDiff line numberDiff line change
@@ -28,21 +28,19 @@ func RenderTemplateToFile(templateContent, destPath, fileName string, data any)
2828
}
2929
tempFilePath := tempFile.Name()
3030
defer os.Remove(tempFilePath) // Clean up temp file when done
31+
defer tempFile.Close()
3132

3233
// Parse and execute template to temp file
3334
tmpl, err := template.New(fileName).Funcs(template.FuncMap{
3435
"toLower": strings.ToLower,
3536
}).Parse(templateContent)
3637
if err != nil {
37-
tempFile.Close()
3838
return err
3939
}
4040

4141
if err := tmpl.Execute(tempFile, data); err != nil {
42-
tempFile.Close()
4342
return err
4443
}
45-
tempFile.Close()
4644

4745
// Run goimports on the temp file
4846
cmd := exec.Command("go", "run", "golang.org/x/tools/cmd/goimports@latest", "-w", tempFilePath)

0 commit comments

Comments
 (0)
Please sign in to comment.