dr200166
2018-12-05 18:01
浏览 109

Golang Docker API:获取事件

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{})
  • 写回答
  • 好问题 提建议
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • dongshenyu4638 2018-12-05 21:45
    已采纳

    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)
            }
     }
    
    已采纳该答案
    评论
    解决 无用
    打赏 举报

相关推荐 更多相似问题