summaryrefslogtreecommitdiff
path: root/pkg/bindings/system
diff options
context:
space:
mode:
authorBrent Baude <bbaude@redhat.com>2020-05-26 16:12:38 -0500
committerBrent Baude <bbaude@redhat.com>2020-05-27 12:16:39 -0500
commit8438fa4fec01142ad9f6943f6e0c429c64d951b7 (patch)
tree476706a57d94e383728e12486e3933c52baf8147 /pkg/bindings/system
parent89b4683cc4666f789ebc3d21453ef65e37775642 (diff)
downloadpodman-8438fa4fec01142ad9f6943f6e0c429c64d951b7.tar.gz
podman-8438fa4fec01142ad9f6943f6e0c429c64d951b7.tar.bz2
podman-8438fa4fec01142ad9f6943f6e0c429c64d951b7.zip
Add streaming ability to endpoint
Signed-off-by: Brent Baude <bbaude@redhat.com>
Diffstat (limited to 'pkg/bindings/system')
-rw-r--r--pkg/bindings/system/system.go29
1 files changed, 19 insertions, 10 deletions
diff --git a/pkg/bindings/system/system.go b/pkg/bindings/system/system.go
index 5348d0cfb..2cd894228 100644
--- a/pkg/bindings/system/system.go
+++ b/pkg/bindings/system/system.go
@@ -20,7 +20,7 @@ import (
// Events allows you to monitor libdpod related events like container creation and
// removal. The events are then passed to the eventChan provided. The optional cancelChan
// can be used to cancel the read of events and close down the HTTP connection.
-func Events(ctx context.Context, eventChan chan (entities.Event), cancelChan chan bool, since, until *string, filters map[string][]string) error {
+func Events(ctx context.Context, eventChan chan entities.Event, cancelChan chan bool, since, until *string, filters map[string][]string, stream *bool) error {
conn, err := bindings.GetClient(ctx)
if err != nil {
return err
@@ -32,6 +32,9 @@ func Events(ctx context.Context, eventChan chan (entities.Event), cancelChan cha
if until != nil {
params.Set("until", *until)
}
+ if stream != nil {
+ params.Set("stream", strconv.FormatBool(*stream))
+ }
if filters != nil {
filterString, err := bindings.FiltersToString(filters)
if err != nil {
@@ -50,18 +53,24 @@ func Events(ctx context.Context, eventChan chan (entities.Event), cancelChan cha
logrus.Error(errors.Wrap(err, "unable to close event response body"))
}()
}
+
dec := json.NewDecoder(response.Body)
- for {
- e := entities.Event{}
- if err := dec.Decode(&e); err != nil {
- if err == io.EOF {
- break
- }
- return errors.Wrap(err, "unable to decode event response")
+ for err = (error)(nil); err == nil; {
+ var e = entities.Event{}
+ err = dec.Decode(&e)
+ if err == nil {
+ eventChan <- e
}
- eventChan <- e
}
- return nil
+ close(eventChan)
+ switch {
+ case err == nil:
+ return nil
+ case errors.Is(err, io.EOF):
+ return nil
+ default:
+ return errors.Wrap(err, "unable to decode event response")
+ }
}
// Prune removes all unused system data.