client: consistently use defer for ensureReaderClosed

ensureReaderClosed was designed to be usable regardless if a response
was nil (error) or non-nil (success). Some code-paths were optimized to
avoid using a defer (which used to have an overhead), but the overhead
of defer is neglectable in current versions of Go, and some of these
optimizations made the logic more complicated (and err-prone).

This patch switches to use a defer for all places.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
Sebastiaan van Stijn
2025-08-12 23:39:45 +02:00
parent f6b63e6013
commit 1c34ff94bc
54 changed files with 60 additions and 60 deletions

View File

@@ -9,6 +9,6 @@ import (
// SwarmUnlock unlocks locked swarm.
func (cli *Client) SwarmUnlock(ctx context.Context, req swarm.UnlockRequest) error {
resp, err := cli.post(ctx, "/swarm/unlock", nil, req, nil)
ensureReaderClosed(resp)
defer ensureReaderClosed(resp)
return err
}