router/static: implement noop watcher (#2031)
* router/static: implement noop watcher * proxy/mucp: handle nil watcher
This commit is contained in:
@@ -297,6 +297,9 @@ func (p *Proxy) watchRoutes() {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
logger.Debugf("Error watching router: %v", err)
|
logger.Debugf("Error watching router: %v", err)
|
||||||
return
|
return
|
||||||
|
} else if w == nil {
|
||||||
|
logger.Debugf("Error watching routes, no watcher returned")
|
||||||
|
return
|
||||||
}
|
}
|
||||||
defer w.Stop()
|
defer w.Stop()
|
||||||
|
|
||||||
|
@@ -63,8 +63,11 @@ func (s *static) Lookup(service string, opts ...router.LookupOption) ([]router.R
|
|||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Watch will return a noop watcher
|
||||||
func (s *static) Watch(opts ...router.WatchOption) (router.Watcher, error) {
|
func (s *static) Watch(opts ...router.WatchOption) (router.Watcher, error) {
|
||||||
return nil, nil
|
return &watcher{
|
||||||
|
events: make(chan *router.Event),
|
||||||
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *static) Close() error {
|
func (s *static) Close() error {
|
||||||
@@ -74,3 +77,24 @@ func (s *static) Close() error {
|
|||||||
func (s *static) String() string {
|
func (s *static) String() string {
|
||||||
return "static"
|
return "static"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// watcher is a noop implementation
|
||||||
|
type watcher struct {
|
||||||
|
events chan *router.Event
|
||||||
|
}
|
||||||
|
|
||||||
|
// Next is a blocking call that returns watch result
|
||||||
|
func (w *watcher) Next() (*router.Event, error) {
|
||||||
|
e := <-w.events
|
||||||
|
return e, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// Chan returns event channel
|
||||||
|
func (w *watcher) Chan() (<-chan *router.Event, error) {
|
||||||
|
return w.events, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// Stop stops watcher
|
||||||
|
func (w *watcher) Stop() {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
Reference in New Issue
Block a user