Files
moby/client/volume_update.go
Sebastiaan van Stijn 1c34ff94bc 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>
2025-08-13 01:17:32 +02:00

29 lines
724 B
Go

package client
import (
"context"
"net/url"
"github.com/moby/moby/api/types/swarm"
"github.com/moby/moby/api/types/volume"
)
// VolumeUpdate updates a volume. This only works for Cluster Volumes, and
// only some fields can be updated.
func (cli *Client) VolumeUpdate(ctx context.Context, volumeID string, version swarm.Version, options volume.UpdateOptions) error {
volumeID, err := trimID("volume", volumeID)
if err != nil {
return err
}
if err := cli.NewVersionError(ctx, "1.42", "volume update"); err != nil {
return err
}
query := url.Values{}
query.Set("version", version.String())
resp, err := cli.put(ctx, "/volumes/"+volumeID, query, options, nil)
defer ensureReaderClosed(resp)
return err
}