Skip to content
This repository has been archived by the owner on Mar 18, 2024. It is now read-only.

Update StartMonitorEvents support MonitorEventsOptions option, and MonitorEventsFilters support label #221

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ func main() {
docker.StopContainer(containerId, 5)

// Listen to events
docker.StartMonitorEvents(eventCallback, nil)
docker.StartMonitorEvents(nil, eventCallback, nil)

// Hold the execution to look at the events coming
time.Sleep(3600 * time.Second)
Expand Down
7 changes: 5 additions & 2 deletions dockerclient.go
Original file line number Diff line number Diff line change
Expand Up @@ -450,6 +450,9 @@ func (client *DockerClient) MonitorEvents(options *MonitorEventsOptions, stopCha
if len(options.Filters.Container) > 0 {
filterMap["container"] = []string{options.Filters.Container}
}
if len(options.Filters.Label) > 0 {
filterMap["label"] = []string{options.Filters.Label}
}
if len(filterMap) > 0 {
filterJSONBytes, err := json.Marshal(filterMap)
if err != nil {
Expand Down Expand Up @@ -488,11 +491,11 @@ func (client *DockerClient) MonitorEvents(options *MonitorEventsOptions, stopCha
return eventOrErrorChan, nil
}

func (client *DockerClient) StartMonitorEvents(cb Callback, ec chan error, args ...interface{}) {
func (client *DockerClient) StartMonitorEvents(options *MonitorEventsOptions, cb Callback, ec chan error, args ...interface{}) {
client.eventStopChan = make(chan struct{})

go func() {
eventErrChan, err := client.MonitorEvents(nil, client.eventStopChan)
eventErrChan, err := client.MonitorEvents(options, client.eventStopChan)
if err != nil {
if ec != nil {
ec <- err
Expand Down
2 changes: 1 addition & 1 deletion examples/events.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ func main() {

client = docker

client.StartMonitorEvents(eventCallback, nil)
client.StartMonitorEvents(nil, eventCallback, nil)

waitForInterrupt()
}
2 changes: 1 addition & 1 deletion interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ type Client interface {
// events will be sent. If a stop channel is provided, events will stop
// being monitored after the stop channel is closed.
MonitorEvents(options *MonitorEventsOptions, stopChan <-chan struct{}) (<-chan EventOrError, error)
StartMonitorEvents(cb Callback, ec chan error, args ...interface{})
StartMonitorEvents(options *MonitorEventsOptions, cb Callback, ec chan error, args ...interface{})
StopAllMonitorEvents()
StartMonitorStats(id string, cb StatCallback, ec chan error, args ...interface{})
StopAllMonitorStats()
Expand Down
4 changes: 2 additions & 2 deletions mockclient/mock.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,8 @@ func (client *MockClient) MonitorEvents(options *dockerclient.MonitorEventsOptio
return args.Get(0).(<-chan dockerclient.EventOrError), args.Error(1)
}

func (client *MockClient) StartMonitorEvents(cb dockerclient.Callback, ec chan error, args ...interface{}) {
client.Mock.Called(cb, ec, args)
func (client *MockClient) StartMonitorEvents(options *dockerclient.MonitorEventsOptions, cb dockerclient.Callback, ec chan error, args ...interface{}) {
client.Mock.Called(options, cb, ec, args)
}

func (client *MockClient) StopAllMonitorEvents() {
Expand Down
2 changes: 1 addition & 1 deletion nopclient/nop.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ func (client *NopClient) MonitorEvents(options *dockerclient.MonitorEventsOption
return nil, ErrNoEngine
}

func (client *NopClient) StartMonitorEvents(cb dockerclient.Callback, ec chan error, args ...interface{}) {
func (client *NopClient) StartMonitorEvents(options *dockerclient.MonitorEventsOptions, cb dockerclient.Callback, ec chan error, args ...interface{}) {
return
}

Expand Down
2 changes: 2 additions & 0 deletions types.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ type MonitorEventsFilters struct {
Event string `json:",omitempty"`
Image string `json:",omitempty"`
Container string `json:",omitempty"`
Label string `json:",omitempty"`
}

type MonitorEventsOptions struct {
Expand Down Expand Up @@ -233,6 +234,7 @@ type ContainerInfo struct {
Gateway string
Bridge string
Ports map[string][]PortBinding
Networks map[string]*EndpointSettings
}
SysInitPath string
ResolvConfPath string
Expand Down