Files
moby/client/volume_create.go
Sebastiaan van Stijn b20c3db932 client: request: use consistent order or arguments
Make `body` the last argument, so that requests can be inlined on call-sites.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2026-08-29 14:14:26 +02:00

42 lines
1.1 KiB
Go

package client
import (
"context"
"encoding/json"
"github.com/moby/moby/api/types/volume"
)
// VolumeCreateOptions specifies the options to create a volume.
type VolumeCreateOptions struct {
Name string
Driver string
DriverOpts map[string]string
Labels map[string]string
ClusterVolumeSpec *volume.ClusterVolumeSpec
}
// VolumeCreateResult is the result of a volume creation.
type VolumeCreateResult struct {
Volume volume.Volume
}
// VolumeCreate creates a volume in the docker host.
func (cli *Client) VolumeCreate(ctx context.Context, options VolumeCreateOptions) (VolumeCreateResult, error) {
resp, err := cli.post(ctx, "/volumes/create", nil, nil, volume.CreateRequest{
Name: options.Name,
Driver: options.Driver,
DriverOpts: options.DriverOpts,
Labels: options.Labels,
ClusterVolumeSpec: options.ClusterVolumeSpec,
})
defer ensureReaderClosed(resp)
if err != nil {
return VolumeCreateResult{}, err
}
var v volume.Volume
err = json.NewDecoder(resp.Body).Decode(&v)
return VolumeCreateResult{Volume: v}, err
}