浏览代码

Address a few staticcheck suggestions

Tormod Erevik Lea 6 年之前
父节点
当前提交
c8f961f633
共有 10 个文件被更改,包括 14 次插入16 次删除
  1. 1 1
      admin.go
  2. 1 1
      admin_test.go
  3. 1 1
      broker.go
  4. 1 2
      client.go
  5. 2 2
      config.go
  6. 2 2
      consumer.go
  7. 3 3
      mockresponses.go
  8. 2 2
      offset_commit_request.go
  9. 0 1
      offset_manager.go
  10. 1 1
      produce_set.go

+ 1 - 1
admin.go

@@ -131,7 +131,7 @@ func (ca *clusterAdmin) CreateTopic(topic string, detail *TopicDetail, validateO
 	}
 	}
 
 
 	if detail == nil {
 	if detail == nil {
-		return errors.New("You must specify topic details")
+		return errors.New("you must specify topic details")
 	}
 	}
 
 
 	topicDetails := make(map[string]*TopicDetail)
 	topicDetails := make(map[string]*TopicDetail)

+ 1 - 1
admin_test.go

@@ -97,7 +97,7 @@ func TestClusterAdminCreateTopicWithInvalidTopicDetail(t *testing.T) {
 	}
 	}
 
 
 	err = admin.CreateTopic("my_topic", nil, false)
 	err = admin.CreateTopic("my_topic", nil, false)
-	if err.Error() != "You must specify topic details" {
+	if err.Error() != "you must specify topic details" {
 		t.Fatal(err)
 		t.Fatal(err)
 	}
 	}
 	err = admin.Close()
 	err = admin.Close()

+ 1 - 1
broker.go

@@ -1097,7 +1097,7 @@ func buildClientInitialResponse(token *AccessToken) ([]byte, error) {
 
 
 	if token.Extensions != nil && len(token.Extensions) > 0 {
 	if token.Extensions != nil && len(token.Extensions) > 0 {
 		if _, ok := token.Extensions[SASLExtKeyAuth]; ok {
 		if _, ok := token.Extensions[SASLExtKeyAuth]; ok {
-			return []byte{}, fmt.Errorf("The extension `%s` is invalid", SASLExtKeyAuth)
+			return []byte{}, fmt.Errorf("the extension `%s` is invalid", SASLExtKeyAuth)
 		}
 		}
 		ext = "\x01" + mapToString(token.Extensions, "=", "\x01")
 		ext = "\x01" + mapToString(token.Extensions, "=", "\x01")
 	}
 	}

+ 1 - 2
client.go

@@ -793,7 +793,7 @@ func (client *client) updateMetadata(data *MetadataResponse, allKnownMetaData bo
 
 
 		switch topic.Err {
 		switch topic.Err {
 		case ErrNoError:
 		case ErrNoError:
-			break
+			// no-op
 		case ErrInvalidTopic, ErrTopicAuthorizationFailed: // don't retry, don't store partial results
 		case ErrInvalidTopic, ErrTopicAuthorizationFailed: // don't retry, don't store partial results
 			err = topic.Err
 			err = topic.Err
 			continue
 			continue
@@ -803,7 +803,6 @@ func (client *client) updateMetadata(data *MetadataResponse, allKnownMetaData bo
 			continue
 			continue
 		case ErrLeaderNotAvailable: // retry, but store partial partition results
 		case ErrLeaderNotAvailable: // retry, but store partial partition results
 			retry = true
 			retry = true
-			break
 		default: // don't retry, don't store partial results
 		default: // don't retry, don't store partial results
 			Logger.Printf("Unexpected topic-level metadata error: %s", topic.Err)
 			Logger.Printf("Unexpected topic-level metadata error: %s", topic.Err)
 			err = topic.Err
 			err = topic.Err

+ 2 - 2
config.go

@@ -419,10 +419,10 @@ func NewConfig() *Config {
 // ConfigurationError if the specified values don't make sense.
 // ConfigurationError if the specified values don't make sense.
 func (c *Config) Validate() error {
 func (c *Config) Validate() error {
 	// some configuration values should be warned on but not fail completely, do those first
 	// some configuration values should be warned on but not fail completely, do those first
-	if c.Net.TLS.Enable == false && c.Net.TLS.Config != nil {
+	if !c.Net.TLS.Enable && c.Net.TLS.Config != nil {
 		Logger.Println("Net.TLS is disabled but a non-nil configuration was provided.")
 		Logger.Println("Net.TLS is disabled but a non-nil configuration was provided.")
 	}
 	}
-	if c.Net.SASL.Enable == false {
+	if !c.Net.SASL.Enable {
 		if c.Net.SASL.User != "" {
 		if c.Net.SASL.User != "" {
 			Logger.Println("Net.SASL is disabled but a non-empty username was provided.")
 			Logger.Println("Net.SASL is disabled but a non-empty username was provided.")
 		}
 		}

+ 2 - 2
consumer.go

@@ -746,7 +746,7 @@ func (bc *brokerConsumer) updateSubscriptions(newSubscriptions []*partitionConsu
 			close(child.trigger)
 			close(child.trigger)
 			delete(bc.subscriptions, child)
 			delete(bc.subscriptions, child)
 		default:
 		default:
-			break
+			// no-op
 		}
 		}
 	}
 	}
 }
 }
@@ -759,7 +759,7 @@ func (bc *brokerConsumer) handleResponses() {
 
 
 		switch result {
 		switch result {
 		case nil:
 		case nil:
-			break
+			// no-op
 		case errTimedOut:
 		case errTimedOut:
 			Logger.Printf("consumer/broker/%d abandoned subscription to %s/%d because consuming was taking too long\n",
 			Logger.Printf("consumer/broker/%d abandoned subscription to %s/%d because consuming was taking too long\n",
 				bc.broker.ID(), child.topic, child.partition)
 				bc.broker.ID(), child.topic, child.partition)

+ 3 - 3
mockresponses.go

@@ -626,7 +626,7 @@ func (mr *MockCreateTopicsResponse) For(reqBody versionedDecoder) encoder {
 	}
 	}
 	res.TopicErrors = make(map[string]*TopicError)
 	res.TopicErrors = make(map[string]*TopicError)
 
 
-	for topic, _ := range req.TopicDetails {
+	for topic := range req.TopicDetails {
 		if res.Version >= 1 && strings.HasPrefix(topic, "_") {
 		if res.Version >= 1 && strings.HasPrefix(topic, "_") {
 			msg := "insufficient permissions to create topic with reserved prefix"
 			msg := "insufficient permissions to create topic with reserved prefix"
 			res.TopicErrors[topic] = &TopicError{
 			res.TopicErrors[topic] = &TopicError{
@@ -672,7 +672,7 @@ func (mr *MockCreatePartitionsResponse) For(reqBody versionedDecoder) encoder {
 	res := &CreatePartitionsResponse{}
 	res := &CreatePartitionsResponse{}
 	res.TopicPartitionErrors = make(map[string]*TopicPartitionError)
 	res.TopicPartitionErrors = make(map[string]*TopicPartitionError)
 
 
-	for topic, _ := range req.TopicPartitions {
+	for topic := range req.TopicPartitions {
 		if strings.HasPrefix(topic, "_") {
 		if strings.HasPrefix(topic, "_") {
 			msg := "insufficient permissions to create partition on topic with reserved prefix"
 			msg := "insufficient permissions to create partition on topic with reserved prefix"
 			res.TopicPartitionErrors[topic] = &TopicPartitionError{
 			res.TopicPartitionErrors[topic] = &TopicPartitionError{
@@ -701,7 +701,7 @@ func (mr *MockDeleteRecordsResponse) For(reqBody versionedDecoder) encoder {
 
 
 	for topic, deleteRecordRequestTopic := range req.Topics {
 	for topic, deleteRecordRequestTopic := range req.Topics {
 		partitions := make(map[int32]*DeleteRecordsResponsePartition)
 		partitions := make(map[int32]*DeleteRecordsResponsePartition)
-		for partition, _ := range deleteRecordRequestTopic.PartitionOffsets {
+		for partition := range deleteRecordRequestTopic.PartitionOffsets {
 			partitions[partition] = &DeleteRecordsResponsePartition{Err: ErrNoError}
 			partitions[partition] = &DeleteRecordsResponsePartition{Err: ErrNoError}
 		}
 		}
 		res.Topics[topic] = &DeleteRecordsResponseTopic{Partitions: partitions}
 		res.Topics[topic] = &DeleteRecordsResponseTopic{Partitions: partitions}

+ 2 - 2
offset_commit_request.go

@@ -200,11 +200,11 @@ func (r *OffsetCommitRequest) AddBlock(topic string, partitionID int32, offset i
 func (r *OffsetCommitRequest) Offset(topic string, partitionID int32) (int64, string, error) {
 func (r *OffsetCommitRequest) Offset(topic string, partitionID int32) (int64, string, error) {
 	partitions := r.blocks[topic]
 	partitions := r.blocks[topic]
 	if partitions == nil {
 	if partitions == nil {
-		return 0, "", errors.New("No such offset")
+		return 0, "", errors.New("no such offset")
 	}
 	}
 	block := partitions[partitionID]
 	block := partitions[partitionID]
 	if block == nil {
 	if block == nil {
-		return 0, "", errors.New("No such offset")
+		return 0, "", errors.New("no such offset")
 	}
 	}
 	return block.offset, block.metadata, nil
 	return block.offset, block.metadata, nil
 }
 }

+ 0 - 1
offset_manager.go

@@ -333,7 +333,6 @@ func (om *offsetManager) handleResponse(broker *Broker, req *OffsetCommitRequest
 				pom.handleError(err)
 				pom.handleError(err)
 			case ErrOffsetsLoadInProgress:
 			case ErrOffsetsLoadInProgress:
 				// nothing wrong but we didn't commit, we'll get it next time round
 				// nothing wrong but we didn't commit, we'll get it next time round
-				break
 			case ErrUnknownTopicOrPartition:
 			case ErrUnknownTopicOrPartition:
 				// let the user know *and* try redispatching - if topic-auto-create is
 				// let the user know *and* try redispatching - if topic-auto-create is
 				// enabled, redispatching should trigger a metadata req and create the
 				// enabled, redispatching should trigger a metadata req and create the

+ 1 - 1
produce_set.go

@@ -81,7 +81,7 @@ func (ps *produceSet) add(msg *ProducerMessage) error {
 
 
 	if ps.parent.conf.Version.IsAtLeast(V0_11_0_0) {
 	if ps.parent.conf.Version.IsAtLeast(V0_11_0_0) {
 		if ps.parent.conf.Producer.Idempotent && msg.sequenceNumber < set.recordsToSend.RecordBatch.FirstSequence {
 		if ps.parent.conf.Producer.Idempotent && msg.sequenceNumber < set.recordsToSend.RecordBatch.FirstSequence {
-			return errors.New("Assertion failed: Message out of sequence added to a batch")
+			return errors.New("assertion failed: message out of sequence added to a batch")
 		}
 		}
 		// We are being conservative here to avoid having to prep encode the record
 		// We are being conservative here to avoid having to prep encode the record
 		size += maximumRecordOverhead
 		size += maximumRecordOverhead