Skip to content

Commit 9670d93

Browse files
committed
api/types: move ContainerListOptions to api/types/container
Signed-off-by: Sebastiaan van Stijn <[email protected]>
1 parent 7bce33e commit 9670d93

24 files changed

Lines changed: 78 additions & 62 deletions

File tree

api/server/router/container/backend.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ type monitorBackend interface {
5353
ContainerLogs(ctx context.Context, name string, config *types.ContainerLogsOptions) (msgs <-chan *backend.LogMessage, tty bool, err error)
5454
ContainerStats(ctx context.Context, name string, config *backend.ContainerStatsConfig) error
5555
ContainerTop(name string, psArgs string) (*container.ContainerTopOKBody, error)
56-
Containers(ctx context.Context, config *types.ContainerListOptions) ([]*types.Container, error)
56+
Containers(ctx context.Context, config *container.ListOptions) ([]*types.Container, error)
5757
}
5858

5959
// attachBackend includes function to implement to provide container attaching functionality.

api/server/router/container/container_routes.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ func (s *containerRouter) getContainersJSON(ctx context.Context, w http.Response
7878
return err
7979
}
8080

81-
config := &types.ContainerListOptions{
81+
config := &container.ListOptions{
8282
All: httputils.BoolValue(r, "all"),
8383
Size: httputils.BoolValue(r, "size"),
8484
Since: r.Form.Get("since"),

api/types/client.go

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -20,17 +20,6 @@ type ContainerExecInspect struct {
2020
Pid int
2121
}
2222

23-
// ContainerListOptions holds parameters to list containers with.
24-
type ContainerListOptions struct {
25-
Size bool
26-
All bool
27-
Latest bool
28-
Since string
29-
Before string
30-
Limit int
31-
Filters filters.Args
32-
}
33-
3423
// ContainerLogsOptions holds parameters to filter logs with.
3524
type ContainerLogsOptions struct {
3625
ShowStdout bool

api/types/container/options.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package container
22

3+
import "github.com/docker/docker/api/types/filters"
4+
35
// ResizeOptions holds parameters to resize a TTY.
46
// It can be used to resize container TTYs and
57
// exec process TTYs too.
@@ -40,3 +42,14 @@ type StartOptions struct {
4042
CheckpointID string
4143
CheckpointDir string
4244
}
45+
46+
// ListOptions holds parameters to list containers with.
47+
type ListOptions struct {
48+
Size bool
49+
All bool
50+
Latest bool
51+
Since string
52+
Before string
53+
Limit int
54+
Filters filters.Args
55+
}

api/types/types_deprecated.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,11 @@ type ContainerAttachOptions = container.AttachOptions
114114
// Deprecated: use [container.CommitOptions].
115115
type ContainerCommitOptions = container.CommitOptions
116116

117+
// ContainerListOptions holds parameters to list containers with.
118+
//
119+
// Deprecated: use [container.ListOptions].
120+
type ContainerListOptions = container.ListOptions
121+
117122
// ContainerRemoveOptions holds parameters to remove containers.
118123
//
119124
// Deprecated: use [container.RemoveOptions].

client/client.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ For example, to list running containers (the equivalent of "docker ps"):
1919
"context"
2020
"fmt"
2121
22-
"github.com/docker/docker/api/types"
22+
"github.com/docker/docker/api/types/container"
2323
"github.com/docker/docker/client"
2424
)
2525
@@ -29,13 +29,13 @@ For example, to list running containers (the equivalent of "docker ps"):
2929
panic(err)
3030
}
3131
32-
containers, err := cli.ContainerList(context.Background(), types.ContainerListOptions{})
32+
containers, err := cli.ContainerList(context.Background(), container.ListOptions{})
3333
if err != nil {
3434
panic(err)
3535
}
3636
37-
for _, container := range containers {
38-
fmt.Printf("%s %s\n", container.ID[:10], container.Image)
37+
for _, ctr := range containers {
38+
fmt.Printf("%s %s\n", ctr.ID, ctr.Image)
3939
}
4040
}
4141
*/

client/container_list.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,12 @@ import (
77
"strconv"
88

99
"github.com/docker/docker/api/types"
10+
"github.com/docker/docker/api/types/container"
1011
"github.com/docker/docker/api/types/filters"
1112
)
1213

1314
// ContainerList returns the list of containers in the docker host.
14-
func (cli *Client) ContainerList(ctx context.Context, options types.ContainerListOptions) ([]types.Container, error) {
15+
func (cli *Client) ContainerList(ctx context.Context, options container.ListOptions) ([]types.Container, error) {
1516
query := url.Values{}
1617

1718
if options.All {

client/container_list_test.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111
"testing"
1212

1313
"github.com/docker/docker/api/types"
14+
"github.com/docker/docker/api/types/container"
1415
"github.com/docker/docker/api/types/filters"
1516
"github.com/docker/docker/errdefs"
1617
"gotest.tools/v3/assert"
@@ -21,7 +22,7 @@ func TestContainerListError(t *testing.T) {
2122
client := &Client{
2223
client: newMockClient(errorMock(http.StatusInternalServerError, "Server error")),
2324
}
24-
_, err := client.ContainerList(context.Background(), types.ContainerListOptions{})
25+
_, err := client.ContainerList(context.Background(), container.ListOptions{})
2526
assert.Check(t, is.ErrorType(err, errdefs.IsSystem))
2627
}
2728

@@ -78,7 +79,7 @@ func TestContainerList(t *testing.T) {
7879
}),
7980
}
8081

81-
containers, err := client.ContainerList(context.Background(), types.ContainerListOptions{
82+
containers, err := client.ContainerList(context.Background(), container.ListOptions{
8283
Size: true,
8384
All: true,
8485
Since: "container",

client/interface.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ type ContainerAPIClient interface {
5959
ContainerInspect(ctx context.Context, container string) (types.ContainerJSON, error)
6060
ContainerInspectWithRaw(ctx context.Context, container string, getSize bool) (types.ContainerJSON, []byte, error)
6161
ContainerKill(ctx context.Context, container, signal string) error
62-
ContainerList(ctx context.Context, options types.ContainerListOptions) ([]types.Container, error)
62+
ContainerList(ctx context.Context, options container.ListOptions) ([]types.Container, error)
6363
ContainerLogs(ctx context.Context, container string, options types.ContainerLogsOptions) (io.ReadCloser, error)
6464
ContainerPause(ctx context.Context, container string) error
6565
ContainerRemove(ctx context.Context, container string, options container.RemoveOptions) error

client/request_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import (
1212
"testing"
1313
"time"
1414

15-
"github.com/docker/docker/api/types"
15+
"github.com/docker/docker/api/types/container"
1616
"github.com/docker/docker/errdefs"
1717
"gotest.tools/v3/assert"
1818
is "gotest.tools/v3/assert/cmp"
@@ -90,7 +90,7 @@ func TestPlainTextError(t *testing.T) {
9090
client := &Client{
9191
client: newMockClient(plainTextErrorMock(http.StatusInternalServerError, "Server error")),
9292
}
93-
_, err := client.ContainerList(context.Background(), types.ContainerListOptions{})
93+
_, err := client.ContainerList(context.Background(), container.ListOptions{})
9494
assert.Check(t, is.ErrorType(err, errdefs.IsSystem))
9595
}
9696

0 commit comments

Comments
 (0)