Skip to content
This repository was archived by the owner on Mar 18, 2024. It is now read-only.
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions dockerclient.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,11 @@ func (client *DockerClient) Info() (*Info, error) {
}

func (client *DockerClient) ListContainers(all bool, size bool, filters string) ([]Container, error) {
return client.ListContainersWithOptions(all, size, "", "", "", filters)
}

// ListContainersWithOptions behaves like ListContainers but allowing additionnal options
func (client *DockerClient) ListContainersWithOptions(all, size bool, limit, since, before, filters string) ([]Container, error) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think these options would be nicer as a struct, something like:

type ListContainerOptions struct {
    All, Size bool
    Limit, Since, Before, Filters string
}

argAll := 0
if all == true {
argAll = 1
Expand All @@ -139,8 +144,21 @@ func (client *DockerClient) ListContainers(all bool, size bool, filters string)
if size == true {
showSize = 1
}

uri := fmt.Sprintf("/%s/containers/json?all=%d&size=%d", APIVersion, argAll, showSize)

if limit != "" {
uri += "&limit=" + limit
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

logic like this is a lot nicer using a url.Values e.g. https://github.com/samalba/dockerclient/blob/master/dockerclient.go#L628

I'd rather include all and size in the url.Values as well, and move the uri creation to after populating the url.Values:

url := fmt.Sprintf("/%s/containers/json?%s", v.Encode())

}

if since != "" {
uri += "&since=" + since
}

if before != "" {
uri += "&before=" + before
}

if filters != "" {
uri += "&filters=" + filters
}
Expand Down