0

I want to get all new events from docker via the golang integration. The problem is that it returns two channels and I couldn't figure out how to subscribe to them.

cli, err := client.NewClientWithOpts(client.WithVersion("1.37"))
if err != nil {
    panic(err)
}

ctx, _ := context.WithCancel(context.Background())

msg, err := <- cli.Events(ctx, types.EventsOptions{})
derich
  • 181
  • 1
  • 1
  • 11

1 Answers1

2

There are many solutions. A solution could be:

msgs, errs := cli.Events(ctx, types.EventsOptions{})

for {
        select {
          case err := <-errs:print(err)
          case msg := <-msgs:print(msg)
        }
 }
  • Thanks for your answer, I just had to remove the `<-` right before `cli.Events(ctx, types.EventsOptions{})` – derich Dec 06 '18 at 11:20