2020-01-17 17:53:33 +02:00
|
|
|
package service
|
2020-01-16 18:10:15 +02:00
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/micro/go-micro/config/source"
|
2020-01-17 17:53:33 +02:00
|
|
|
proto "github.com/micro/go-micro/config/source/service/proto"
|
2020-01-16 18:10:15 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
type watcher struct {
|
2020-01-17 17:27:41 +02:00
|
|
|
stream proto.Service_WatchService
|
2020-01-16 18:10:15 +02:00
|
|
|
}
|
|
|
|
|
2020-01-17 17:27:41 +02:00
|
|
|
func newWatcher(stream proto.Service_WatchService) (source.Watcher, error) {
|
2020-01-16 18:10:15 +02:00
|
|
|
return &watcher{stream: stream}, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (w *watcher) Next() (*source.ChangeSet, error) {
|
|
|
|
var rsp proto.WatchResponse
|
|
|
|
err := w.stream.RecvMsg(&rsp)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
return toChangeSet(rsp.ChangeSet), nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (w *watcher) Stop() error {
|
|
|
|
return w.stream.Close()
|
|
|
|
}
|