diff --git a/cli/command/container/pause.go b/cli/command/container/pause.go index 8323827e8d..495c1c9f9a 100644 --- a/cli/command/container/pause.go +++ b/cli/command/container/pause.go @@ -32,8 +32,8 @@ func NewPauseCommand(dockerCli command.Cli) *cobra.Command { Annotations: map[string]string{ "aliases": "docker container pause, docker pause", }, - ValidArgsFunction: completion.ContainerNames(dockerCli, false, func(container types.Container) bool { - return container.State != "paused" + ValidArgsFunction: completion.ContainerNames(dockerCli, false, func(ctr types.Container) bool { + return ctr.State != "paused" }), } } @@ -41,12 +41,12 @@ func NewPauseCommand(dockerCli command.Cli) *cobra.Command { func runPause(ctx context.Context, dockerCli command.Cli, opts *pauseOptions) error { var errs []string errChan := parallelOperation(ctx, opts.containers, dockerCli.Client().ContainerPause) - for _, container := range opts.containers { + for _, ctr := range opts.containers { if err := <-errChan; err != nil { errs = append(errs, err.Error()) continue } - fmt.Fprintln(dockerCli.Out(), container) + _, _ = fmt.Fprintln(dockerCli.Out(), ctr) } if len(errs) > 0 { return errors.New(strings.Join(errs, "\n")) diff --git a/cli/command/container/start.go b/cli/command/container/start.go index ba04e34435..7cd6d0e7ce 100644 --- a/cli/command/container/start.go +++ b/cli/command/container/start.go @@ -43,8 +43,8 @@ func NewStartCommand(dockerCli command.Cli) *cobra.Command { Annotations: map[string]string{ "aliases": "docker container start, docker start", }, - ValidArgsFunction: completion.ContainerNames(dockerCli, true, func(container types.Container) bool { - return container.State == "exited" || container.State == "created" + ValidArgsFunction: completion.ContainerNames(dockerCli, true, func(ctr types.Container) bool { + return ctr.State == "exited" || ctr.State == "created" }), } diff --git a/cli/command/container/unpause.go b/cli/command/container/unpause.go index 3d82dcff80..3190d75790 100644 --- a/cli/command/container/unpause.go +++ b/cli/command/container/unpause.go @@ -32,8 +32,8 @@ func NewUnpauseCommand(dockerCli command.Cli) *cobra.Command { Annotations: map[string]string{ "aliases": "docker container unpause, docker unpause", }, - ValidArgsFunction: completion.ContainerNames(dockerCli, false, func(container types.Container) bool { - return container.State == "paused" + ValidArgsFunction: completion.ContainerNames(dockerCli, false, func(ctr types.Container) bool { + return ctr.State == "paused" }), } return cmd @@ -42,12 +42,12 @@ func NewUnpauseCommand(dockerCli command.Cli) *cobra.Command { func runUnpause(ctx context.Context, dockerCli command.Cli, opts *unpauseOptions) error { var errs []string errChan := parallelOperation(ctx, opts.containers, dockerCli.Client().ContainerUnpause) - for _, container := range opts.containers { + for _, ctr := range opts.containers { if err := <-errChan; err != nil { errs = append(errs, err.Error()) continue } - fmt.Fprintln(dockerCli.Out(), container) + _, _ = fmt.Fprintln(dockerCli.Out(), ctr) } if len(errs) > 0 { return errors.New(strings.Join(errs, "\n")) diff --git a/cli/command/container/update.go b/cli/command/container/update.go index 7ea668830b..997d61b354 100644 --- a/cli/command/container/update.go +++ b/cli/command/container/update.go @@ -130,17 +130,17 @@ func runUpdate(ctx context.Context, dockerCli command.Cli, options *updateOption warns []string errs []string ) - for _, container := range options.containers { - r, err := dockerCli.Client().ContainerUpdate(ctx, container, updateConfig) + for _, ctr := range options.containers { + r, err := dockerCli.Client().ContainerUpdate(ctx, ctr, updateConfig) if err != nil { errs = append(errs, err.Error()) } else { - fmt.Fprintln(dockerCli.Out(), container) + _, _ = fmt.Fprintln(dockerCli.Out(), ctr) } warns = append(warns, r.Warnings...) } if len(warns) > 0 { - fmt.Fprintln(dockerCli.Out(), strings.Join(warns, "\n")) + _, _ = fmt.Fprintln(dockerCli.Out(), strings.Join(warns, "\n")) } if len(errs) > 0 { return errors.New(strings.Join(errs, "\n")) diff --git a/cli/command/container/wait.go b/cli/command/container/wait.go index 91cca5b6aa..8eb7d82f80 100644 --- a/cli/command/container/wait.go +++ b/cli/command/container/wait.go @@ -39,12 +39,12 @@ func NewWaitCommand(dockerCli command.Cli) *cobra.Command { func runWait(ctx context.Context, dockerCli command.Cli, opts *waitOptions) error { var errs []string - for _, container := range opts.containers { - resultC, errC := dockerCli.Client().ContainerWait(ctx, container, "") + for _, ctr := range opts.containers { + resultC, errC := dockerCli.Client().ContainerWait(ctx, ctr, "") select { case result := <-resultC: - fmt.Fprintf(dockerCli.Out(), "%d\n", result.StatusCode) + _, _ = fmt.Fprintf(dockerCli.Out(), "%d\n", result.StatusCode) case err := <-errC: errs = append(errs, err.Error()) } diff --git a/cli/command/formatter/container.go b/cli/command/formatter/container.go index aeaa03a6d3..17afec1b4b 100644 --- a/cli/command/formatter/container.go +++ b/cli/command/formatter/container.go @@ -68,8 +68,8 @@ ports: {{- pad .Ports 1 0}} // ContainerWrite renders the context for a list of containers func ContainerWrite(ctx Context, containers []types.Container) error { render := func(format func(subContext SubContext) error) error { - for _, container := range containers { - err := format(&ContainerContext{trunc: ctx.Trunc, c: container}) + for _, ctr := range containers { + err := format(&ContainerContext{trunc: ctx.Trunc, c: ctr}) if err != nil { return err } diff --git a/cli/command/formatter/disk_usage.go b/cli/command/formatter/disk_usage.go index d91df2fc55..cd1d75bef3 100644 --- a/cli/command/formatter/disk_usage.go +++ b/cli/command/formatter/disk_usage.go @@ -336,8 +336,8 @@ func (c *diskUsageContainersContext) isActive(container types.Container) bool { func (c *diskUsageContainersContext) Active() string { used := 0 - for _, container := range c.containers { - if c.isActive(*container) { + for _, ctr := range c.containers { + if c.isActive(*ctr) { used++ } } @@ -348,22 +348,21 @@ func (c *diskUsageContainersContext) Active() string { func (c *diskUsageContainersContext) Size() string { var size int64 - for _, container := range c.containers { - size += container.SizeRw + for _, ctr := range c.containers { + size += ctr.SizeRw } return units.HumanSize(float64(size)) } func (c *diskUsageContainersContext) Reclaimable() string { - var reclaimable int64 - var totalSize int64 + var reclaimable, totalSize int64 - for _, container := range c.containers { - if !c.isActive(*container) { - reclaimable += container.SizeRw + for _, ctr := range c.containers { + if !c.isActive(*ctr) { + reclaimable += ctr.SizeRw } - totalSize += container.SizeRw + totalSize += ctr.SizeRw } if totalSize > 0 { diff --git a/cli/command/image/client_test.go b/cli/command/image/client_test.go index 35bf3ab772..eb3a4cebef 100644 --- a/cli/command/image/client_test.go +++ b/cli/command/image/client_test.go @@ -24,9 +24,9 @@ type fakeClient struct { imagesPruneFunc func(pruneFilter filters.Args) (image.PruneReport, error) imageLoadFunc func(input io.Reader, quiet bool) (image.LoadResponse, error) imageListFunc func(options image.ListOptions) ([]image.Summary, error) - imageInspectFunc func(image string) (types.ImageInspect, []byte, error) + imageInspectFunc func(img string) (types.ImageInspect, []byte, error) imageImportFunc func(source image.ImportSource, ref string, options image.ImportOptions) (io.ReadCloser, error) - imageHistoryFunc func(image string) ([]image.HistoryResponseItem, error) + imageHistoryFunc func(img string) ([]image.HistoryResponseItem, error) imageBuildFunc func(context.Context, io.Reader, types.ImageBuildOptions) (types.ImageBuildResponse, error) } diff --git a/cli/command/image/inspect_test.go b/cli/command/image/inspect_test.go index fd0067e022..1a6425f8c9 100644 --- a/cli/command/image/inspect_test.go +++ b/cli/command/image/inspect_test.go @@ -38,15 +38,15 @@ func TestNewInspectCommandSuccess(t *testing.T) { name string args []string imageCount int - imageInspectFunc func(image string) (types.ImageInspect, []byte, error) + imageInspectFunc func(img string) (types.ImageInspect, []byte, error) }{ { name: "simple", args: []string{"image"}, imageCount: 1, - imageInspectFunc: func(image string) (types.ImageInspect, []byte, error) { + imageInspectFunc: func(img string) (types.ImageInspect, []byte, error) { imageInspectInvocationCount++ - assert.Check(t, is.Equal("image", image)) + assert.Check(t, is.Equal("image", img)) return types.ImageInspect{}, nil, nil }, }, @@ -54,21 +54,21 @@ func TestNewInspectCommandSuccess(t *testing.T) { name: "format", imageCount: 1, args: []string{"--format='{{.ID}}'", "image"}, - imageInspectFunc: func(image string) (types.ImageInspect, []byte, error) { + imageInspectFunc: func(img string) (types.ImageInspect, []byte, error) { imageInspectInvocationCount++ - return types.ImageInspect{ID: image}, nil, nil + return types.ImageInspect{ID: img}, nil, nil }, }, { name: "simple-many", args: []string{"image1", "image2"}, imageCount: 2, - imageInspectFunc: func(image string) (types.ImageInspect, []byte, error) { + imageInspectFunc: func(img string) (types.ImageInspect, []byte, error) { imageInspectInvocationCount++ if imageInspectInvocationCount == 1 { - assert.Check(t, is.Equal("image1", image)) + assert.Check(t, is.Equal("image1", img)) } else { - assert.Check(t, is.Equal("image2", image)) + assert.Check(t, is.Equal("image2", img)) } return types.ImageInspect{}, nil, nil }, diff --git a/cli/command/network/disconnect.go b/cli/command/network/disconnect.go index abed538f66..318a2d2a2b 100644 --- a/cli/command/network/disconnect.go +++ b/cli/command/network/disconnect.go @@ -50,18 +50,18 @@ func runDisconnect(ctx context.Context, dockerCli command.Cli, opts disconnectOp } func isConnected(network string) func(types.Container) bool { - return func(container types.Container) bool { - if container.NetworkSettings == nil { + return func(ctr types.Container) bool { + if ctr.NetworkSettings == nil { return false } - _, ok := container.NetworkSettings.Networks[network] + _, ok := ctr.NetworkSettings.Networks[network] return ok } } func not(fn func(types.Container) bool) func(types.Container) bool { - return func(container types.Container) bool { - ok := fn(container) + return func(ctr types.Container) bool { + ok := fn(ctr) return !ok } } diff --git a/internal/test/builders/container.go b/internal/test/builders/container.go index 0f31998a06..359b14e76a 100644 --- a/internal/test/builders/container.go +++ b/internal/test/builders/container.go @@ -8,10 +8,10 @@ import ( // Container creates a container with default values. // Any number of container function builder can be passed to augment it. -func Container(name string, builders ...func(container *types.Container)) *types.Container { +func Container(name string, builders ...func(c *types.Container)) *types.Container { // now := time.Now() // onehourago := now.Add(-120 * time.Minute) - container := &types.Container{ + ctr := &types.Container{ ID: "container_id", Names: []string{"/" + name}, Command: "top", @@ -21,10 +21,10 @@ func Container(name string, builders ...func(container *types.Container)) *types } for _, builder := range builders { - builder(container) + builder(ctr) } - return container + return ctr } // WithLabel adds a label to the container @@ -45,14 +45,14 @@ func WithName(name string) func(*types.Container) { } // WithPort adds a port mapping to the container -func WithPort(privateport, publicport uint16, builders ...func(*types.Port)) func(*types.Container) { +func WithPort(privatePort, publicPort uint16, builders ...func(*types.Port)) func(*types.Container) { return func(c *types.Container) { if c.Ports == nil { c.Ports = []types.Port{} } port := &types.Port{ - PrivatePort: privateport, - PublicPort: publicport, + PrivatePort: privatePort, + PublicPort: publicPort, } for _, builder := range builders { builder(port)