Переглянути джерело

Cleanup vet and lint warnings.

Gary Burd 12 роки тому
батько
коміт
c759d6c16a
7 змінених файлів з 29 додано та 25 видалено
  1. 3 3
      redis/conn.go
  2. 1 1
      redis/conn_test.go
  3. 3 0
      redis/pool.go
  4. 1 1
      redis/pubsub.go
  5. 9 9
      redis/pubsub_test.go
  6. 1 0
      redis/reply.go
  7. 11 11
      redis/scan.go

+ 3 - 3
redis/conn.go

@@ -390,11 +390,11 @@ func (c *conn) Do(cmd string, args ...interface{}) (interface{}, error) {
 	if cmd == "" {
 		reply := make([]interface{}, pending)
 		for i := range reply {
-			if r, e := c.readReply(); e != nil {
+			r, e := c.readReply()
+			if e != nil {
 				return nil, c.fatal(e)
-			} else {
-				reply[i] = r
 			}
+			reply[i] = r
 		}
 		return reply, nil
 	}

+ 1 - 1
redis/conn_test.go

@@ -193,7 +193,7 @@ func dial() (redis.Conn, error) {
 	}
 
 	if n != 0 {
-		return nil, errors.New("Database #9 is not empty, test can not continue")
+		return nil, errors.New("database #9 is not empty, test can not continue")
 	}
 
 	return testConn{c}, nil

+ 3 - 0
redis/pool.go

@@ -23,7 +23,10 @@ import (
 
 var nowFunc = time.Now // for testing
 
+// ErrPoolExhausted is returned from pool connection methods when the maximum
+// number of database connections in the pool has been reached.
 var ErrPoolExhausted = errors.New("redigo: connection pool exhausted")
+
 var errPoolClosed = errors.New("redigo: connection pool closed")
 
 // Pool maintains a pool of connections. The application calls the Get method

+ 1 - 1
redis/pubsub.go

@@ -18,7 +18,7 @@ import (
 	"errors"
 )
 
-// Subscribe represents a subscribe or unsubscribe notification.
+// Subscription represents a subscribe or unsubscribe notification.
 type Subscription struct {
 
 	// Kind is "subscribe", "unsubscribe", "psubscribe" or "punsubscribe"

+ 9 - 9
redis/pubsub_test.go

@@ -43,7 +43,7 @@ func ExamplePubSubConn() {
 	var wg sync.WaitGroup
 	wg.Add(2)
 
-	psc := redis.PubSubConn{c}
+	psc := redis.PubSubConn{Conn: c}
 
 	// This goroutine receives and prints pushed notifications from the server.
 	// The goroutine exits when the connection is unsubscribed from all
@@ -119,20 +119,20 @@ func TestPushed(t *testing.T) {
 	defer nc.Close()
 	nc.SetReadDeadline(time.Now().Add(4 * time.Second))
 
-	c := redis.PubSubConn{redis.NewConn(nc, 0, 0)}
+	c := redis.PubSubConn{Conn: redis.NewConn(nc, 0, 0)}
 
 	c.Subscribe("c1")
-	expectPushed(t, c, "Subscribe(c1)", redis.Subscription{"subscribe", "c1", 1})
+	expectPushed(t, c, "Subscribe(c1)", redis.Subscription{Kind: "subscribe", Channel: "c1", Count: 1})
 	c.Subscribe("c2")
-	expectPushed(t, c, "Subscribe(c2)", redis.Subscription{"subscribe", "c2", 2})
+	expectPushed(t, c, "Subscribe(c2)", redis.Subscription{Kind: "subscribe", Channel: "c2", Count: 2})
 	c.PSubscribe("p1")
-	expectPushed(t, c, "PSubscribe(p1)", redis.Subscription{"psubscribe", "p1", 3})
+	expectPushed(t, c, "PSubscribe(p1)", redis.Subscription{Kind: "psubscribe", Channel: "p1", Count: 3})
 	c.PSubscribe("p2")
-	expectPushed(t, c, "PSubscribe(p2)", redis.Subscription{"psubscribe", "p2", 4})
+	expectPushed(t, c, "PSubscribe(p2)", redis.Subscription{Kind: "psubscribe", Channel: "p2", Count: 4})
 	c.PUnsubscribe()
-	expectPushed(t, c, "Punsubscribe(p1)", redis.Subscription{"punsubscribe", "p1", 3})
-	expectPushed(t, c, "Punsubscribe()", redis.Subscription{"punsubscribe", "p2", 2})
+	expectPushed(t, c, "Punsubscribe(p1)", redis.Subscription{Kind: "punsubscribe", Channel: "p1", Count: 3})
+	expectPushed(t, c, "Punsubscribe()", redis.Subscription{Kind: "punsubscribe", Channel: "p2", Count: 2})
 
 	pc.Do("PUBLISH", "c1", "hello")
-	expectPushed(t, c, "PUBLISH c1 hello", redis.Message{"c1", []byte("hello")})
+	expectPushed(t, c, "PUBLISH c1 hello", redis.Message{Channel: "c1", Data: []byte("hello")})
 }

+ 1 - 0
redis/reply.go

@@ -20,6 +20,7 @@ import (
 	"strconv"
 )
 
+// ErrNil indicates that a reply value is nil.
 var ErrNil = errors.New("redigo: nil returned")
 
 // Int is a helper that converts a command reply to an integer. If err is not

+ 11 - 11
redis/scan.go

@@ -318,7 +318,7 @@ func structSpecForType(t reflect.Type) *structSpec {
 	return ss
 }
 
-var scanStructValueError = errors.New("redigo: ScanStruct value must be non-nil pointer to a struct.")
+var errScanStructValue = errors.New("redigo: ScanStruct value must be non-nil pointer to a struct")
 
 // ScanStruct scans a multi-bulk src containing alternating names and values to
 // a struct. The HGETALL and CONFIG GET commands return replies in this format.
@@ -339,11 +339,11 @@ var scanStructValueError = errors.New("redigo: ScanStruct value must be non-nil
 func ScanStruct(src []interface{}, dest interface{}) error {
 	d := reflect.ValueOf(dest)
 	if d.Kind() != reflect.Ptr || d.IsNil() {
-		return scanStructValueError
+		return errScanStructValue
 	}
 	d = d.Elem()
 	if d.Kind() != reflect.Struct {
-		return scanStructValueError
+		return errScanStructValue
 	}
 	ss := structSpecForType(d.Type())
 
@@ -380,8 +380,8 @@ func ScanStruct(src []interface{}, dest interface{}) error {
 }
 
 var (
-	scanSliceValueError = errors.New("redigo: ScanSlice dest must be non-nil pointer to a struct.")
-	scanSliceSrcError   = errors.New("redigo: ScanSlice src element must be bulk or nil.")
+	errScanSliceValue = errors.New("redigo: ScanSlice dest must be non-nil pointer to a struct")
+	errScanSliceSrc   = errors.New("redigo: ScanSlice src element must be bulk or nil")
 )
 
 // ScanSlice scans multi-bulk src to the slice pointed to by dest. The elements
@@ -393,11 +393,11 @@ var (
 func ScanSlice(src []interface{}, dest interface{}, fieldNames ...string) error {
 	d := reflect.ValueOf(dest)
 	if d.Kind() != reflect.Ptr || d.IsNil() {
-		return scanSliceValueError
+		return errScanSliceValue
 	}
 	d = d.Elem()
 	if d.Kind() != reflect.Slice {
-		return scanSliceValueError
+		return errScanSliceValue
 	}
 
 	isPtr := false
@@ -415,7 +415,7 @@ func ScanSlice(src []interface{}, dest interface{}, fieldNames ...string) error
 			}
 			s, ok := s.([]byte)
 			if !ok {
-				return scanSliceSrcError
+				return errScanSliceSrc
 			}
 			if err := convertAssignBytes(d.Index(i), s); err != nil {
 				return err
@@ -437,12 +437,12 @@ func ScanSlice(src []interface{}, dest interface{}, fieldNames ...string) error
 	}
 
 	if len(fss) == 0 {
-		return errors.New("redigo: ScanSlice no struct fields.")
+		return errors.New("redigo: ScanSlice no struct fields")
 	}
 
 	n := len(src) / len(fss)
 	if n*len(fss) != len(src) {
-		return errors.New("redigo: ScanSlice length not a multiple of struct field count.")
+		return errors.New("redigo: ScanSlice length not a multiple of struct field count")
 	}
 
 	ensureLen(d, n)
@@ -461,7 +461,7 @@ func ScanSlice(src []interface{}, dest interface{}, fieldNames ...string) error
 			}
 			sb, ok := s.([]byte)
 			if !ok {
-				return scanSliceSrcError
+				return errScanSliceSrc
 			}
 			d := d.FieldByIndex(fs.index)
 			if err := convertAssignBytes(d, sb); err != nil {