func MonitorWithHandler(ctx context.Context, cli client.SystemAPIClient, options types.EventsOptions, handler *Handler) chan error {
	eventChan := make(chan eventtypes.Message)
	errChan := make(chan error)
	started := make(chan struct{})
	go handler.Watch(eventChan)
	go monitorEvents(ctx, cli, options, started, eventChan, errChan)
	go func() {
		for {
			select {
			case <-ctx.Done():
				errChan <- nil
			}
		}
	}()
	<-started
	return errChan
}
MonitorWithHandler subscribes to the docker events api using engine api and will pass the message
to the specified Handler, that will take care of it.
It will pass the specified options to the underline method (i.e Events).
package events
import (
	"encoding/json"
	"io"
	"golang.org/x/net/context"
	"github.com/docker/engine-api/client"
	"github.com/docker/engine-api/types"
	eventtypes "github.com/docker/engine-api/types/events"
)
func Monitor(ctx context.Context, cli client.SystemAPIClient, options types.EventsOptions, fun func(m eventtypes.Message)) chan error {
	handler := NewHandler(func(_ eventtypes.Message) string {
		return ""
	})
	handler.Handle("", fun)
	return MonitorWithHandler(ctx, cli, options, handler)
}