2020-01-17 23:53:33 +08:00
|
|
|
package service
|
2020-01-17 00:10:15 +08:00
|
|
|
|
|
|
|
import (
|
2020-01-30 14:39:00 +03:00
|
|
|
"github.com/micro/go-micro/v2/config/source"
|
|
|
|
proto "github.com/micro/go-micro/v2/config/source/service/proto"
|
2020-01-17 00:10:15 +08:00
|
|
|
)
|
|
|
|
|
|
|
|
type watcher struct {
|
2020-01-23 11:37:54 +00:00
|
|
|
stream proto.Config_WatchService
|
2020-01-17 00:10:15 +08:00
|
|
|
}
|
|
|
|
|
2020-01-23 11:37:54 +00:00
|
|
|
func newWatcher(stream proto.Config_WatchService) (source.Watcher, error) {
|
2020-01-17 00:10:15 +08: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()
|
|
|
|
}
|