samalba / dockerclient

Docker client library in Go
http://www.docker.com/
Apache License 2.0
320 stars 140 forks source link

Allow filtering events on multiple event/containers/images #220

Closed lebauce closed 8 years ago

lebauce commented 8 years ago

Signed-off-by: Sylvain Baubeau sbaubeau@redhat.com

lebauce commented 8 years ago

A less intrusive fix could be :

diff --git a/dockerclient.go b/dockerclient.go
index fb1fdd9..e83a761 100644
--- a/dockerclient.go
+++ b/dockerclient.go
@@ -442,13 +442,13 @@ func (client *DockerClient) MonitorEvents(options *MonitorEventsOptions, stopCha
        if options.Filters != nil {
            filterMap := make(map[string][]string)
            if len(options.Filters.Event) > 0 {
-               filterMap["event"] = []string{options.Filters.Event}
+               filterMap["event"] = strings.Split(options.Filters.Event, ",")
            }
            if len(options.Filters.Image) > 0 {
-               filterMap["image"] = []string{options.Filters.Image}
+               filterMap["image"] = strings.Split(options.Filters.Image, ",")
            }
            if len(options.Filters.Container) > 0 {
-               filterMap["container"] = []string{options.Filters.Container}
+               filterMap["container"] = strings.Split(options.Filters.Container, ",")
            }
            if len(filterMap) > 0 {
                filterJSONBytes, err := json.Marshal(filterMap)

but it may be a bit awkward to use the Event property for specifying multiple events.

lebauce commented 8 years ago

ping @samalba

lebauce commented 8 years ago

ping @vieux @donhcd :-/

donhcd commented 8 years ago

LGTM. fwiw I don't think anybody is really actively maintaining this repo anymore, and docker's supported go client is https://github.com/docker/engine-api and it seems like it does have the filters working the way you want https://github.com/docker/engine-api/blob/master/client/events.go#L36 though the return types are atrocious :(

lebauce commented 8 years ago

@donhcd Thank you.

That may be a good idea to change the "Well maintained docker client library." baseline then :-)