8000 feat: use defer processing error (#98) · mark3labs/mcp-go@62cdf71 · GitHub
[go: up one dir, main page]

Skip to content

Commit 62cdf71

Browse files
authored
feat: use defer processing error (#98)
1 parent 1b7e34c commit 62cdf71

File tree

2 files changed

+2
-4
lines changed

2 files changed

+2
-4
lines changed

client/sse.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -391,7 +391,7 @@ func (c *SSEMCPClient) Initialize(
391391
err,
392392
)
393393
}
394-
resp.Body.Close()
394+
defer resp.Body.Close()
395395

396396
c.initialized = true
397397
return &result, nil

server/internal/gen/main.go

Lines changed: 1 addition & 3 deletions
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)
0