Browse Source

concurrency: return v3.GetResponse for Election.Leader()

The full information about the leader's key is necessary to
safely use elections with transactions. Instead of returning
only the value on Leader(), return the entire GetResposne.
Anthony Romano 8 years ago
parent
commit
4b5bb7f212
1 changed files with 4 additions and 4 deletions
  1. 4 4
      clientv3/concurrency/election.go

+ 4 - 4
clientv3/concurrency/election.go

@@ -122,16 +122,16 @@ func (e *Election) Resign(ctx context.Context) (err error) {
 }
 
 // Leader returns the leader value for the current election.
-func (e *Election) Leader(ctx context.Context) (string, error) {
+func (e *Election) Leader(ctx context.Context) (*v3.GetResponse, error) {
 	client := e.session.Client()
 	resp, err := client.Get(ctx, e.keyPrefix, v3.WithFirstCreate()...)
 	if err != nil {
-		return "", err
+		return nil, err
 	} else if len(resp.Kvs) == 0 {
 		// no leader currently elected
-		return "", ErrElectionNoLeader
+		return nil, ErrElectionNoLeader
 	}
-	return string(resp.Kvs[0].Value), nil
+	return resp, nil
 }
 
 // Observe returns a channel that observes all leader proposal values as