Files
opencloud/vendor/github.com/moby/moby/client/volume_create.go
dependabot[bot] d88bd1aa59 build(deps): bump github.com/testcontainers/testcontainers-go/modules/opensearch
Bumps [github.com/testcontainers/testcontainers-go/modules/opensearch](https://github.com/testcontainers/testcontainers-go) from 0.41.0 to 0.42.0.
- [Release notes](https://github.com/testcontainers/testcontainers-go/releases)
- [Commits](https://github.com/testcontainers/testcontainers-go/compare/v0.41.0...v0.42.0)

---
updated-dependencies:
- dependency-name: github.com/testcontainers/testcontainers-go/modules/opensearch
  dependency-version: 0.42.0
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
2026-04-22 11:29:03 +02:00

43 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) {
createRequest := volume.CreateRequest{
Name: options.Name,
Driver: options.Driver,
DriverOpts: options.DriverOpts,
Labels: options.Labels,
ClusterVolumeSpec: options.ClusterVolumeSpec,
}
resp, err := cli.post(ctx, "/volumes/create", nil, createRequest, nil)
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
}