make WatchOptions and WatchObject fields public (#3218)

This commit is contained in:
César Nieto
2020-05-12 10:42:34 -07:00
committed by GitHub
parent 672390b86a
commit a6d82862cd
6 changed files with 57 additions and 56 deletions
+6 -6
View File
@@ -127,7 +127,7 @@ func (f *fsClient) Select(expression string, sse encrypt.ServerSide, opts Select
}
// Watches for all fs events on an input path.
func (f *fsClient) Watch(params watchParams) (*WatchObject, *probe.Error) {
func (f *fsClient) Watch(options WatchOptions) (*WatchObject, *probe.Error) {
eventChan := make(chan []EventInfo)
errorChan := make(chan *probe.Error)
doneChan := make(chan struct{})
@@ -136,7 +136,7 @@ func (f *fsClient) Watch(params watchParams) (*WatchObject, *probe.Error) {
in, out := PipeChan(1000)
var fsEvents []notify.Event
for _, event := range params.events {
for _, event := range options.Events {
switch event {
case "put":
fsEvents = append(fsEvents, EventTypePut...)
@@ -152,7 +152,7 @@ func (f *fsClient) Watch(params watchParams) (*WatchObject, *probe.Error) {
// Set up a watchpoint listening for events within a directory tree rooted
// at current working directory. Dispatch remove events to c.
recursivePath := f.PathURL.Path
if params.recursive {
if options.Recursive {
recursivePath = f.PathURL.Path + "..."
}
if e := notify.Watch(recursivePath, in, fsEvents...); e != nil {
@@ -216,9 +216,9 @@ func (f *fsClient) Watch(params watchParams) (*WatchObject, *probe.Error) {
}()
return &WatchObject{
eventInfoChan: eventChan,
errorChan: errorChan,
doneChan: doneChan,
EventInfoChan: eventChan,
ErrorChan: errorChan,
DoneChan: doneChan,
}, nil
}
+10 -10
View File
@@ -727,13 +727,13 @@ func (c *S3Client) notificationToEventsInfo(ninfo minio.NotificationInfo) []Even
}
// Watch - Start watching on all bucket events for a given account ID.
func (c *S3Client) Watch(params watchParams) (*WatchObject, *probe.Error) {
func (c *S3Client) Watch(options WatchOptions) (*WatchObject, *probe.Error) {
// Extract bucket and object.
bucket, object := c.url2BucketAndObject()
// Flag set to set the notification.
var events []string
for _, event := range params.events {
for _, event := range options.Events {
switch event {
case "put":
events = append(events, string(minio.ObjectCreatedAll))
@@ -745,11 +745,11 @@ func (c *S3Client) Watch(params watchParams) (*WatchObject, *probe.Error) {
return nil, errInvalidArgument().Trace(event)
}
}
if object != "" && params.prefix != "" {
return nil, errInvalidArgument().Trace(params.prefix, object)
if object != "" && options.Prefix != "" {
return nil, errInvalidArgument().Trace(options.Prefix, object)
}
if object != "" && params.prefix == "" {
params.prefix = object
if object != "" && options.Prefix == "" {
options.Prefix = object
}
// The list of buckets to watch
@@ -767,9 +767,9 @@ func (c *S3Client) Watch(params watchParams) (*WatchObject, *probe.Error) {
}
wo := &WatchObject{
eventInfoChan: make(chan []EventInfo),
errorChan: make(chan *probe.Error),
doneChan: make(chan struct{}),
EventInfoChan: make(chan []EventInfo),
ErrorChan: make(chan *probe.Error),
DoneChan: make(chan struct{}),
}
var wg sync.WaitGroup
@@ -779,7 +779,7 @@ func (c *S3Client) Watch(params watchParams) (*WatchObject, *probe.Error) {
go func() {
defer wg.Done()
// Start listening on all bucket events.
eventsCh := c.api.ListenBucketNotification(bucket, params.prefix, params.suffix, events, wo.doneChan)
eventsCh := c.api.ListenBucketNotification(bucket, options.Prefix, options.Suffix, events, wo.DoneChan)
for notificationInfo := range eventsCh {
if notificationInfo.Err != nil {
var perr *probe.Error
+1 -1
View File
@@ -79,7 +79,7 @@ type Client interface {
ShareUpload(bool, time.Duration, string) (string, map[string]string, *probe.Error)
// Watch events
Watch(params watchParams) (*WatchObject, *probe.Error)
Watch(options WatchOptions) (*WatchObject, *probe.Error)
// Delete operations
Remove(isIncomplete, isRemoveBucket, isBypass bool, contentCh <-chan *ClientContent) (errorCh <-chan *probe.Error)
+6 -6
View File
@@ -136,19 +136,19 @@ func watchFind(ctx *findContext) {
if !ctx.watch {
return
}
params := watchParams{
recursive: true,
events: []string{"put"},
options := WatchOptions{
Recursive: true,
Events: []string{"put"},
}
watchObj, err := ctx.clnt.Watch(params)
fatalIf(err.Trace(ctx.targetAlias), "Cannot watch with given params.")
watchObj, err := ctx.clnt.Watch(options)
fatalIf(err.Trace(ctx.targetAlias), "Cannot watch with given options.")
// Loop until user CTRL-C the command line.
for {
select {
case <-globalContext.Done():
console.Println()
close(watchObj.doneChan)
close(watchObj.DoneChan)
return
case events, ok := <-watchObj.Events():
if !ok {
+7 -7
View File
@@ -150,15 +150,15 @@ func mainWatch(ctx *cli.Context) error {
fatalIf(pErr.Trace(), "Cannot parse the provided url.")
}
params := watchParams{
recursive: recursive,
events: events,
prefix: prefix,
suffix: suffix,
options := WatchOptions{
Recursive: recursive,
Events: events,
Prefix: prefix,
Suffix: suffix,
}
// Start watching on events
wo, err := s3Client.Watch(params)
wo, err := s3Client.Watch(options)
fatalIf(err, "Cannot watch on the specified bucket.")
// Initialize.. waitgroup to track the go-routine.
@@ -176,7 +176,7 @@ func mainWatch(ctx *cli.Context) error {
select {
case <-globalContext.Done():
// Signal received we are done.
close(wo.doneChan)
close(wo.DoneChan)
return
case events, ok := <-wo.Events():
if !ok {
+27 -26
View File
@@ -65,39 +65,40 @@ type EventInfo struct {
UserAgent string
}
type watchParams struct {
prefix string
suffix string
events []string
recursive bool
// WatchOptions contains watch configuration options
type WatchOptions struct {
Prefix string
Suffix string
Events []string
Recursive bool
}
// WatchObject captures watch channels to read and listen on.
type WatchObject struct {
// eventInfo will be put on this chan
eventInfoChan chan []EventInfo
EventInfoChan chan []EventInfo
// errors will be put on this chan
errorChan chan *probe.Error
ErrorChan chan *probe.Error
// will stop the watcher goroutines
doneChan chan struct{}
DoneChan chan struct{}
}
// Events returns the chan receiving events
func (w *WatchObject) Events() chan []EventInfo {
return w.eventInfoChan
return w.EventInfoChan
}
// Errors returns the chan receiving errors
func (w *WatchObject) Errors() chan *probe.Error {
return w.errorChan
return w.ErrorChan
}
// Close the watcher, will stop all goroutines
func (w *WatchObject) Close() {
// Cleanup
close(w.eventInfoChan)
close(w.errorChan)
close(w.doneChan)
close(w.EventInfoChan)
close(w.ErrorChan)
close(w.DoneChan)
}
// Watcher can be used to have one or multiple clients watch for notifications
@@ -105,9 +106,9 @@ type Watcher struct {
sessionStartTime time.Time
// all error will be added to this chan
errorChan chan *probe.Error
ErrorChan chan *probe.Error
// all events will be added to this chan
eventInfoChan chan []EventInfo
EventInfoChan chan []EventInfo
// array of watchers joined
o []*WatchObject
@@ -120,20 +121,20 @@ type Watcher struct {
func NewWatcher(sessionStartTime time.Time) *Watcher {
return &Watcher{
sessionStartTime: sessionStartTime,
errorChan: make(chan *probe.Error),
eventInfoChan: make(chan []EventInfo),
ErrorChan: make(chan *probe.Error),
EventInfoChan: make(chan []EventInfo),
o: []*WatchObject{},
}
}
// Errors returns a channel which will receive errors
func (w *Watcher) Errors() chan *probe.Error {
return w.errorChan
return w.ErrorChan
}
// Events returns a channel which will receive events
func (w *Watcher) Events() chan []EventInfo {
return w.eventInfoChan
return w.EventInfoChan
}
// Stop watcher
@@ -145,8 +146,8 @@ func (w *Watcher) Stop() {
w.wg.Wait()
close(w.errorChan)
close(w.eventInfoChan)
close(w.ErrorChan)
close(w.EventInfoChan)
}
// Watching returns if the watcher is watching for notifications
@@ -161,9 +162,9 @@ func (w *Watcher) Wait() {
// Join the watcher with client
func (w *Watcher) Join(client Client, recursive bool) *probe.Error {
wo, err := client.Watch(watchParams{
recursive: recursive,
events: []string{"put", "delete"},
wo, err := client.Watch(WatchOptions{
Recursive: recursive,
Events: []string{"put", "delete"},
})
if err != nil {
return err
@@ -185,13 +186,13 @@ func (w *Watcher) Join(client Client, recursive bool) *probe.Error {
if !ok {
return
}
w.eventInfoChan <- events
w.EventInfoChan <- events
case err, ok := <-wo.Errors():
if !ok {
return
}
w.errorChan <- err
w.ErrorChan <- err
}
}
}()