mirror of
https://github.com/moby/moby.git
synced 2026-01-11 02:31:44 +00:00
client/container_exec.go:8:2: import "github.com/containerd/errdefs" imported without alias but must be with alias "cerrdefs" according to config (importas)
"github.com/containerd/errdefs"
^
client/container_exec_test.go:9:2: import "github.com/containerd/errdefs" imported without alias but must be with alias "cerrdefs" according to config (importas)
"github.com/containerd/errdefs"
^
client/container_rename.go:8:2: import "github.com/containerd/errdefs" imported without alias but must be with alias "cerrdefs" according to config (importas)
"github.com/containerd/errdefs"
^
client/pkg/security/security_opts_test.go:8:2: import "gotest.tools/v3/assert/cmp" imported without alias but must be with alias "is" according to config (importas)
"gotest.tools/v3/assert/cmp"
^
client/volume_prune.go:9:2: import "github.com/containerd/errdefs" imported without alias but must be with alias "cerrdefs" according to config (importas)
"github.com/containerd/errdefs"
^
client/volume_prune_test.go:8:2: import "github.com/containerd/errdefs" imported without alias but must be with alias "cerrdefs" according to config (importas)
"github.com/containerd/errdefs"
^
client/container_exec_test.go:10:2: ST1019(related information): other import of "github.com/containerd/errdefs" (staticcheck)
cerrdefs "github.com/containerd/errdefs"
^
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
40 lines
1.3 KiB
Go
40 lines
1.3 KiB
Go
package client
|
|
|
|
import (
|
|
"context"
|
|
"net/url"
|
|
"strings"
|
|
|
|
cerrdefs "github.com/containerd/errdefs"
|
|
)
|
|
|
|
// ContainerRenameOptions represents the options for renaming a container.
|
|
type ContainerRenameOptions struct {
|
|
NewName string
|
|
}
|
|
|
|
// ContainerRenameResult represents the result of a container rename operation.
|
|
type ContainerRenameResult struct {
|
|
// This struct can be expanded in the future if needed
|
|
}
|
|
|
|
// ContainerRename changes the name of a given container.
|
|
func (cli *Client) ContainerRename(ctx context.Context, containerID string, options ContainerRenameOptions) (ContainerRenameResult, error) {
|
|
containerID, err := trimID("container", containerID)
|
|
if err != nil {
|
|
return ContainerRenameResult{}, err
|
|
}
|
|
options.NewName = strings.TrimSpace(options.NewName)
|
|
if options.NewName == "" || strings.TrimPrefix(options.NewName, "/") == "" {
|
|
// daemons before v29.0 did not handle the canonical name ("/") well
|
|
// let's be nice and validate it here before sending
|
|
return ContainerRenameResult{}, cerrdefs.ErrInvalidArgument.WithMessage("new name cannot be blank")
|
|
}
|
|
|
|
query := url.Values{}
|
|
query.Set("name", options.NewName)
|
|
resp, err := cli.post(ctx, "/containers/"+containerID+"/rename", query, nil, nil)
|
|
defer ensureReaderClosed(resp)
|
|
return ContainerRenameResult{}, err
|
|
}
|