1
0
mirror of https://github.com/go-micro/go-micro.git synced 2024-12-24 10:07:04 +02:00
go-micro/config/source/service/watcher.go

28 lines
572 B
Go
Raw Normal View History

package service
2020-01-16 18:10:15 +02:00
import (
"github.com/micro/go-micro/v2/config/source"
proto "github.com/micro/go-micro/v2/config/source/service/proto"
2020-01-16 18:10:15 +02:00
)
type watcher struct {
2020-01-23 13:37:54 +02:00
stream proto.Config_WatchService
2020-01-16 18:10:15 +02:00
}
2020-01-23 13:37:54 +02:00
func newWatcher(stream proto.Config_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()
}