Browse Source

clientv3: define error type for closed watcher

Gyu-Ho Lee 8 năm trước cách đây
mục cha
commit
5f4412996d
1 tập tin đã thay đổi với 4 bổ sung1 xóa
  1. 4 1
      clientv3/naming/grpc.go

+ 4 - 1
clientv3/naming/grpc.go

@@ -16,6 +16,7 @@ package naming
 
 import (
 	"encoding/json"
+	"fmt"
 
 	etcd "github.com/coreos/etcd/clientv3"
 	"golang.org/x/net/context"
@@ -25,6 +26,8 @@ import (
 	"google.golang.org/grpc/naming"
 )
 
+var ErrWatcherClosed = fmt.Errorf("naming: watch closed")
+
 // GRPCResolver creates a grpc.Watcher for a target to track its resolution changes.
 type GRPCResolver struct {
 	// Client is an initialized etcd client.
@@ -77,7 +80,7 @@ func (gw *gRPCWatcher) Next() ([]*naming.Update, error) {
 	// process new events on target/*
 	wr, ok := <-gw.wch
 	if !ok {
-		gw.err = grpc.Errorf(codes.Unavailable, "naming: watch closed")
+		gw.err = grpc.Errorf(codes.Unavailable, "%s", ErrWatcherClosed)
 		return nil, gw.err
 	}
 	if gw.err = wr.Err(); gw.err != nil {