From dcf8e00db62b4b0df9f1cd43f0bbeac6b7d1580a Mon Sep 17 00:00:00 2001 From: Varun Kumar Date: Sun, 5 Jul 2020 14:19:09 -0500 Subject: [PATCH] fixed declaration dependencies and other lint issues --- api_versions_request_test.go | 2 +- async_producer_test.go | 4 ++-- broker.go | 4 ++-- client.go | 2 +- consumer.go | 2 +- examples/README.md | 2 -- examples/sasl_scram_client/main.go | 4 ++-- mockresponses.go | 12 ++++++------ .../kafka-console-producer/kafka-console-producer.go | 2 +- tools/kafka-producer-performance/main.go | 2 +- 10 files changed, 17 insertions(+), 19 deletions(-) diff --git a/api_versions_request_test.go b/api_versions_request_test.go index be86e6271..4bb2fdac3 100644 --- a/api_versions_request_test.go +++ b/api_versions_request_test.go @@ -3,7 +3,7 @@ package sarama import "testing" var ( - apiVersionRequest = []byte{} + apiVersionRequest []byte ) func TestApiVersionsRequest(t *testing.T) { diff --git a/async_producer_test.go b/async_producer_test.go index 46b97790a..d6669f36d 100644 --- a/async_producer_test.go +++ b/async_producer_test.go @@ -11,7 +11,7 @@ import ( "time" "github.com/fortytw2/leaktest" - metrics "github.com/rcrowley/go-metrics" + "github.com/rcrowley/go-metrics" ) const TestMessage = "ABC THE MESSAGE" @@ -91,7 +91,7 @@ func (f flakyEncoder) Length() int { } func (f flakyEncoder) Encode() ([]byte, error) { - if !bool(f) { + if !f { return nil, errors.New("flaky encoding error") } return []byte(TestMessage), nil diff --git a/broker.go b/broker.go index 232559aea..5858a23c0 100644 --- a/broker.go +++ b/broker.go @@ -13,7 +13,7 @@ import ( "sync/atomic" "time" - metrics "github.com/rcrowley/go-metrics" + "github.com/rcrowley/go-metrics" ) // Broker represents a single Kafka broker connection. All operations on this object are entirely concurrency-safe. @@ -1027,7 +1027,7 @@ func (b *Broker) sendAndReceiveV0SASLPlainAuth() error { length := len(b.conf.Net.SASL.AuthIdentity) + 1 + len(b.conf.Net.SASL.User) + 1 + len(b.conf.Net.SASL.Password) authBytes := make([]byte, length+4) //4 byte length header + auth data binary.BigEndian.PutUint32(authBytes, uint32(length)) - copy(authBytes[4:], []byte(b.conf.Net.SASL.AuthIdentity+"\x00"+b.conf.Net.SASL.User+"\x00"+b.conf.Net.SASL.Password)) + copy(authBytes[4:], b.conf.Net.SASL.AuthIdentity+"\x00"+b.conf.Net.SASL.User+"\x00"+b.conf.Net.SASL.Password) requestTime := time.Now() // Will be decremented in updateIncomingCommunicationMetrics (except error) diff --git a/client.go b/client.go index c3392f961..b29519342 100644 --- a/client.go +++ b/client.go @@ -788,7 +788,7 @@ func (client *client) backgroundMetadataUpdater() { } func (client *client) refreshMetadata() error { - topics := []string{} + var topics []string if !client.conf.Metadata.Full { if specificTopics, err := client.MetadataTopics(); err != nil { diff --git a/consumer.go b/consumer.go index e16d08aa9..8ccd31057 100644 --- a/consumer.go +++ b/consumer.go @@ -623,7 +623,7 @@ func (child *partitionConsumer) parseResponse(response *FetchResponse) ([]*Consu abortedProducerIDs := make(map[int64]struct{}, len(block.AbortedTransactions)) abortedTransactions := block.getAbortedTransactions() - messages := []*ConsumerMessage{} + var messages []*ConsumerMessage for _, records := range block.RecordsSet { switch records.recordsType { case legacyRecords: diff --git a/examples/README.md b/examples/README.md index 4c32436bc..b7db36365 100644 --- a/examples/README.md +++ b/examples/README.md @@ -8,5 +8,3 @@ In these examples, we use `github.com/Shopify/sarama` as import path. We do this [http_server](./http_server) is a simple HTTP server uses both the sync producer to produce data as part of the request handling cycle, as well as the async producer to maintain an access log. It also uses the [mocks subpackage](https://godoc.org/github.com/Shopify/sarama/mocks) to test both. -#### SASL SCRAM Authentication -[sasl_scram_authentication](./sasl_scram_authentication) is an example of how to authenticate to a Kafka cluster using SASL SCRAM-SHA-256 or SCRAM-SHA-512 mechanisms. diff --git a/examples/sasl_scram_client/main.go b/examples/sasl_scram_client/main.go index b359b23d8..884949b7d 100644 --- a/examples/sasl_scram_client/main.go +++ b/examples/sasl_scram_client/main.go @@ -91,10 +91,10 @@ func main() { conf.Net.SASL.Handshake = true if *algorithm == "sha512" { conf.Net.SASL.SCRAMClientGeneratorFunc = func() sarama.SCRAMClient { return &XDGSCRAMClient{HashGeneratorFcn: SHA512} } - conf.Net.SASL.Mechanism = sarama.SASLMechanism(sarama.SASLTypeSCRAMSHA512) + conf.Net.SASL.Mechanism = sarama.SASLTypeSCRAMSHA512 } else if *algorithm == "sha256" { conf.Net.SASL.SCRAMClientGeneratorFunc = func() sarama.SCRAMClient { return &XDGSCRAMClient{HashGeneratorFcn: SHA256} } - conf.Net.SASL.Mechanism = sarama.SASLMechanism(sarama.SASLTypeSCRAMSHA256) + conf.Net.SASL.Mechanism = sarama.SASLTypeSCRAMSHA256 } else { log.Fatalf("invalid SHA algorithm \"%s\": can be either \"sha256\" or \"sha512\"", *algorithm) diff --git a/mockresponses.go b/mockresponses.go index 2560da8af..be8af8545 100644 --- a/mockresponses.go +++ b/mockresponses.go @@ -177,8 +177,8 @@ func (mmr *MockMetadataResponse) For(reqBody versionedDecoder) encoderWithHeader } // Generate set of replicas - replicas := []int32{} - offlineReplicas := []int32{} + var replicas []int32 + var offlineReplicas []int32 for _, brokerID := range mmr.brokers { replicas = append(replicas, brokerID) } @@ -772,8 +772,8 @@ func (mr *MockDescribeConfigsResponse) For(reqBody versionedDecoder) encoderWith Version: req.Version, } - includeSynonyms := (req.Version > 0) - includeSource := (req.Version > 0) + includeSynonyms := req.Version > 0 + includeSource := req.Version > 0 for _, r := range req.Resources { var configEntries []*ConfigEntry @@ -1088,9 +1088,9 @@ func NewMockDescribeLogDirsResponse(t TestReporter) *MockDescribeLogDirsResponse } func (m *MockDescribeLogDirsResponse) SetLogDirs(logDirPath string, topicPartitions map[string]int) *MockDescribeLogDirsResponse { - topics := []DescribeLogDirsResponseTopic{} + var topics []DescribeLogDirsResponseTopic for topic := range topicPartitions { - partitions := []DescribeLogDirsResponsePartition{} + var partitions []DescribeLogDirsResponsePartition for i := 0; i < topicPartitions[topic]; i++ { partitions = append(partitions, DescribeLogDirsResponsePartition{ PartitionID: int32(i), diff --git a/tools/kafka-console-producer/kafka-console-producer.go b/tools/kafka-console-producer/kafka-console-producer.go index b88e1f1c0..75decbb56 100644 --- a/tools/kafka-console-producer/kafka-console-producer.go +++ b/tools/kafka-console-producer/kafka-console-producer.go @@ -102,7 +102,7 @@ func main() { } if *headers != "" { - hdrs := []sarama.RecordHeader{} + var hdrs []sarama.RecordHeader arrHdrs := strings.Split(*headers, ",") for _, h := range arrHdrs { if header := strings.Split(h, ":"); len(header) != 2 { diff --git a/tools/kafka-producer-performance/main.go b/tools/kafka-producer-performance/main.go index b155011d9..2d40431d8 100644 --- a/tools/kafka-producer-performance/main.go +++ b/tools/kafka-producer-performance/main.go @@ -14,7 +14,7 @@ import ( gosync "sync" "time" - metrics "github.com/rcrowley/go-metrics" + "github.com/rcrowley/go-metrics" "github.com/Shopify/sarama" "github.com/Shopify/sarama/tools/tls"