mirror of
				https://github.com/moby/moby.git
				synced 2022-11-09 12:21:53 -05:00 
			
		
		
		
	- Move time json marshaling to the jsonlog package: this is a docker internal hack that we should not promote as a library. - Move Timestamp encoding/decoding functions to the API types: This is only used there. It could be a standalone library but I don't this it's worth having a separated repo for this. It could introduce more complexity than it solves. Signed-off-by: David Calavera <david.calavera@gmail.com>
		
			
				
	
	
		
			46 lines
		
	
	
	
		
			1,023 B
		
	
	
	
		
			Go
		
	
	
	
	
	
			
		
		
	
	
			46 lines
		
	
	
	
		
			1,023 B
		
	
	
	
		
			Go
		
	
	
	
	
	
package lib
 | 
						|
 | 
						|
import (
 | 
						|
	"io"
 | 
						|
	"net/url"
 | 
						|
	"time"
 | 
						|
 | 
						|
	"github.com/docker/docker/api/types"
 | 
						|
	timetypes "github.com/docker/docker/api/types/time"
 | 
						|
	"github.com/docker/docker/pkg/parsers/filters"
 | 
						|
)
 | 
						|
 | 
						|
// Events returns a stream of events in the daemon in a ReadCloser.
 | 
						|
// It's up to the caller to close the stream.
 | 
						|
func (cli *Client) Events(options types.EventsOptions) (io.ReadCloser, error) {
 | 
						|
	query := url.Values{}
 | 
						|
	ref := time.Now()
 | 
						|
 | 
						|
	if options.Since != "" {
 | 
						|
		ts, err := timetypes.GetTimestamp(options.Since, ref)
 | 
						|
		if err != nil {
 | 
						|
			return nil, err
 | 
						|
		}
 | 
						|
		query.Set("since", ts)
 | 
						|
	}
 | 
						|
	if options.Until != "" {
 | 
						|
		ts, err := timetypes.GetTimestamp(options.Until, ref)
 | 
						|
		if err != nil {
 | 
						|
			return nil, err
 | 
						|
		}
 | 
						|
		query.Set("until", ts)
 | 
						|
	}
 | 
						|
	if options.Filters.Len() > 0 {
 | 
						|
		filterJSON, err := filters.ToParam(options.Filters)
 | 
						|
		if err != nil {
 | 
						|
			return nil, err
 | 
						|
		}
 | 
						|
		query.Set("filters", filterJSON)
 | 
						|
	}
 | 
						|
 | 
						|
	serverResponse, err := cli.get("/events", query, nil)
 | 
						|
	if err != nil {
 | 
						|
		return nil, err
 | 
						|
	}
 | 
						|
	return serverResponse.body, nil
 | 
						|
}
 |