Skip to content

Commit cc6b7a1

Browse files
build: add golangci-lint to circleci config (#907)
1 parent aedfa48 commit cc6b7a1

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

55 files changed

+155
-566
lines changed

.circleci/config.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
version: 2
22
jobs:
3+
lint:
4+
docker:
5+
- image: golangci/golangci-lint:v1.45-alpine
6+
steps:
7+
- checkout
8+
- run: golangci-lint run
9+
310
# The kafka 0.10 tests are maintained as a separate configuration because
411
# kafka only supported plain text SASL in this version.
512
kafka-010:
@@ -287,6 +294,7 @@ workflows:
287294
version: 2
288295
run:
289296
jobs:
297+
- lint
290298
- kafka-010
291299
- kafka-011
292300
- kafka-101

.golangci.yml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
linters:
2+
enable:
3+
- bodyclose
4+
- goconst
5+
- godot
6+
- gofmt
7+
- goimports
8+
- prealloc
9+
10+
disable:
11+
# Temporarily disabling so it can be addressed in a dedicated PR.
12+
- errcheck
13+
- errorlint
14+
- goerr113

alterconfigs.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import (
99
"github.com/segmentio/kafka-go/protocol/alterconfigs"
1010
)
1111

12-
// AlterConfigsRequest represents a request sent to a kafka broker to alter configs
12+
// AlterConfigsRequest represents a request sent to a kafka broker to alter configs.
1313
type AlterConfigsRequest struct {
1414
// Address of the kafka broker to send the request to.
1515
Addr net.Addr
@@ -54,7 +54,8 @@ type AlterConfigsResponse struct {
5454
Errors map[AlterConfigsResponseResource]error
5555
}
5656

57-
// AlterConfigsResponseResource
57+
// AlterConfigsResponseResource helps map errors to specific resources in an
58+
// alter config response.
5859
type AlterConfigsResponseResource struct {
5960
Type int8
6061
Name string

alterconfigs_test.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,10 @@ func TestClientAlterConfigs(t *testing.T) {
4949
}},
5050
})
5151

52+
if err != nil {
53+
t.Fatal(err)
54+
}
55+
5256
maxMessageBytesValue := "0"
5357
for _, resource := range describeResp.Resources {
5458
if resource.ResourceType == int8(ResourceTypeTopic) && resource.ResourceName == topic {

balancer.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ var (
126126
//
127127
// By default, Hash uses the FNV-1a algorithm. This is the same algorithm used
128128
// by the Sarama Producer and ensures that messages produced by kafka-go will
129-
// be delivered to the same topics that the Sarama producer would be delivered to
129+
// be delivered to the same topics that the Sarama producer would be delivered to.
130130
type Hash struct {
131131
rr RoundRobin
132132
Hasher hash.Hash32

builder_test.go

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ func (f v1MessageSetBuilder) bytes() []byte {
147147
})
148148
if f.codec != nil {
149149
bs = newWB().call(func(wb *kafkaWriteBuffer) {
150-
wb.writeInt64(f.msgs[len(f.msgs)-1].Offset) // offset of the wrapper message is the last offset of the inner messages
150+
wb.writeInt64(f.msgs[len(f.msgs)-1].Offset) // offset of the wrapper message is the last offset of the inner messages
151151
wb.writeBytes(newWB().call(func(wb *kafkaWriteBuffer) {
152152
bs := mustCompress(bs, f.codec)
153153
wb.writeInt32(-1) // crc, unused
@@ -194,14 +194,14 @@ func (f v2MessageSetBuilder) bytes() []byte {
194194
for i, msg := range f.msgs {
195195
wb.Write(newWB().call(func(wb *kafkaWriteBuffer) {
196196
bs := newWB().call(func(wb *kafkaWriteBuffer) {
197-
wb.writeInt8(0) // record attributes, not used here
198-
wb.writeVarInt(1000 * (time.Now().Unix() - msg.Time.Unix())) // timestamp
199-
wb.writeVarInt(int64(i)) // offset delta
200-
wb.writeVarInt(int64(len(msg.Key))) // key len
201-
wb.Write(msg.Key) // key bytes
202-
wb.writeVarInt(int64(len(msg.Value))) // value len
203-
wb.Write(msg.Value) // value bytes
204-
wb.writeVarInt(int64(len(msg.Headers))) // number of headers
197+
wb.writeInt8(0) // record attributes, not used here
198+
wb.writeVarInt(1000 * (time.Now().Unix() - msg.Time.Unix())) // timestamp
199+
wb.writeVarInt(int64(i)) // offset delta
200+
wb.writeVarInt(int64(len(msg.Key))) // key len
201+
wb.Write(msg.Key) // key bytes
202+
wb.writeVarInt(int64(len(msg.Value))) // value len
203+
wb.Write(msg.Value) // value bytes
204+
wb.writeVarInt(int64(len(msg.Headers))) // number of headers
205205
for _, header := range msg.Headers {
206206
wb.writeVarInt(int64(len(header.Key)))
207207
wb.Write([]byte(header.Key))
@@ -222,7 +222,7 @@ func (f v2MessageSetBuilder) bytes() []byte {
222222
})
223223
}
224224

225-
// kafkaWriteBuffer is a write buffer that helps writing fetch responses
225+
// kafkaWriteBuffer is a write buffer that helps writing fetch responses.
226226
type kafkaWriteBuffer struct {
227227
writeBuffer
228228
buf bytes.Buffer

compress/compress_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -372,7 +372,7 @@ func BenchmarkCompression(b *testing.B) {
372372
benchmark := &benchmarks[i]
373373
ratio := 0.0
374374

375-
b.Run(fmt.Sprintf("%s", benchmark.codec.Name()), func(b *testing.B) {
375+
b.Run(benchmark.codec.Name(), func(b *testing.B) {
376376
ratio = benchmark.function(b, benchmark.codec, &buffer, payload)
377377
})
378378

compress/snappy/go-xerial-snappy/snappy.go

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -16,19 +16,19 @@ const (
1616
var (
1717
xerialHeader = []byte{130, 83, 78, 65, 80, 80, 89, 0}
1818

19-
// This is xerial version 1 and minimally compatible with version 1
19+
// This is xerial version 1 and minimally compatible with version 1.
2020
xerialVersionInfo = []byte{0, 0, 0, 1, 0, 0, 0, 1}
2121

2222
// ErrMalformed is returned by the decoder when the xerial framing
23-
// is malformed
23+
// is malformed.
2424
ErrMalformed = errors.New("malformed xerial framing")
2525
)
2626

2727
func min(x, y int) int {
28-
if x < y {
29-
return x
30-
}
31-
return y
28+
if x < y {
29+
return x
30+
}
31+
return y
3232
}
3333

3434
// Encode encodes data as snappy with no framing header.
@@ -48,14 +48,14 @@ func EncodeStream(dst, src []byte) []byte {
4848

4949
// Snappy encode in blocks of maximum 32KB
5050
var (
51-
max = len(src)
51+
max = len(src)
5252
blockSize = 32 * 1024
53-
pos = 0
54-
chunk []byte
53+
pos = 0
54+
chunk []byte
5555
)
5656

5757
for pos < max {
58-
newPos := min(pos + blockSize, max)
58+
newPos := min(pos+blockSize, max)
5959
chunk = master.Encode(chunk[:cap(chunk)], src[pos:newPos])
6060

6161
// First encode the compressed size (big-endian)
@@ -104,7 +104,7 @@ func DecodeInto(dst, src []byte) ([]byte, error) {
104104
var (
105105
pos = sizeOffset
106106
chunk []byte
107-
err error
107+
err error
108108
)
109109

110110
for pos+sizeBytes <= max {

compress/snappy/go-xerial-snappy/snappy_test.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,17 +16,17 @@ var snappyTestCases = map[string][]byte{
1616
var snappyStreamTestCases = map[string][]byte{
1717
"PLAINDATA": {130, 83, 78, 65, 80, 80, 89, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 11, 9, 32, 80, 76, 65, 73, 78, 68, 65, 84, 65},
1818
`{"a":"UtaitILHMDAAAAfU","b":"日本"}`: {130, 83, 78, 65, 80, 80, 89, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 39, 37, 144, 123, 34, 97, 34, 58, 34, 85, 116, 97, 105, 116, 73, 76, 72, 77, 68, 65, 65, 65, 65, 102, 85, 34, 44, 34, 98, 34, 58, 34, 230, 151, 165, 230, 156, 172, 34, 125},
19-
largeString: {130, 83, 78, 65, 80, 80, 89, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 3, 89, 128, 8, 240, 90, 83, 101, 100, 32, 117, 116, 32, 112, 101, 114, 115, 112, 105, 99, 105, 97, 116, 105, 115, 32, 117, 110, 100, 101, 32, 111, 109, 110, 105, 115, 32, 105, 115, 116, 101, 32, 110, 97, 116, 117, 115, 32, 101, 114, 114, 111, 114, 32, 115, 105, 116, 32, 118, 111, 108, 117, 112, 116, 97, 116, 101, 109, 32, 97, 99, 99, 117, 115, 97, 110, 116, 105, 117, 109, 32, 100, 111, 108, 111, 114, 101, 109, 113, 117, 101, 32, 108, 97, 117, 100, 97, 5, 22, 240, 60, 44, 32, 116, 111, 116, 97, 109, 32, 114, 101, 109, 32, 97, 112, 101, 114, 105, 97, 109, 44, 32, 101, 97, 113, 117, 101, 32, 105, 112, 115, 97, 32, 113, 117, 97, 101, 32, 97, 98, 32, 105, 108, 108, 111, 32, 105, 110, 118, 101, 110, 116, 111, 114, 101, 32, 118, 101, 114, 105, 116, 97, 1, 141, 4, 101, 116, 1, 36, 88, 115, 105, 32, 97, 114, 99, 104, 105, 116, 101, 99, 116, 111, 32, 98, 101, 97, 116, 97, 101, 32, 118, 105, 1, 6, 120, 100, 105, 99, 116, 97, 32, 115, 117, 110, 116, 32, 101, 120, 112, 108, 105, 99, 97, 98, 111, 46, 32, 78, 101, 109, 111, 32, 101, 110, 105, 109, 5, 103, 0, 109, 46, 180, 0, 12, 113, 117, 105, 97, 17, 16, 0, 115, 5, 209, 72, 97, 115, 112, 101, 114, 110, 97, 116, 117, 114, 32, 97, 117, 116, 32, 111, 100, 105, 116, 5, 9, 36, 102, 117, 103, 105, 116, 44, 32, 115, 101, 100, 9, 53, 32, 99, 111, 110, 115, 101, 113, 117, 117, 110, 1, 42, 20, 109, 97, 103, 110, 105, 32, 9, 245, 16, 115, 32, 101, 111, 115, 1, 36, 28, 32, 114, 97, 116, 105, 111, 110, 101, 17, 96, 33, 36, 1, 51, 36, 105, 32, 110, 101, 115, 99, 105, 117, 110, 116, 1, 155, 1, 254, 16, 112, 111, 114, 114, 111, 1, 51, 36, 115, 113, 117, 97, 109, 32, 101, 115, 116, 44, 1, 14, 13, 81, 5, 183, 4, 117, 109, 1, 18, 0, 97, 9, 19, 4, 32, 115, 1, 149, 12, 109, 101, 116, 44, 9, 135, 76, 99, 116, 101, 116, 117, 114, 44, 32, 97, 100, 105, 112, 105, 115, 99, 105, 32, 118, 101, 108, 50, 173, 0, 24, 110, 111, 110, 32, 110, 117, 109, 9, 94, 84, 105, 117, 115, 32, 109, 111, 100, 105, 32, 116, 101, 109, 112, 111, 114, 97, 32, 105, 110, 99, 105, 100, 33, 52, 20, 117, 116, 32, 108, 97, 98, 33, 116, 4, 101, 116, 9, 106, 0, 101, 5, 219, 20, 97, 109, 32, 97, 108, 105, 5, 62, 33, 164, 8, 114, 97, 116, 29, 212, 12, 46, 32, 85, 116, 41, 94, 52, 97, 100, 32, 109, 105, 110, 105, 109, 97, 32, 118, 101, 110, 105, 33, 221, 72, 113, 117, 105, 115, 32, 110, 111, 115, 116, 114, 117, 109, 32, 101, 120, 101, 114, 99, 105, 33, 202, 104, 111, 110, 101, 109, 32, 117, 108, 108, 97, 109, 32, 99, 111, 114, 112, 111, 114, 105, 115, 32, 115, 117, 115, 99, 105, 112, 105, 13, 130, 8, 105, 111, 115, 1, 64, 12, 110, 105, 115, 105, 1, 150, 5, 126, 44, 105, 100, 32, 101, 120, 32, 101, 97, 32, 99, 111, 109, 5, 192, 0, 99, 41, 131, 33, 172, 8, 63, 32, 81, 1, 107, 4, 97, 117, 33, 101, 96, 118, 101, 108, 32, 101, 117, 109, 32, 105, 117, 114, 101, 32, 114, 101, 112, 114, 101, 104, 101, 110, 100, 101, 114, 105, 65, 63, 12, 105, 32, 105, 110, 1, 69, 16, 118, 111, 108, 117, 112, 65, 185, 1, 47, 24, 105, 116, 32, 101, 115, 115, 101, 1, 222, 64, 109, 32, 110, 105, 104, 105, 108, 32, 109, 111, 108, 101, 115, 116, 105, 97, 101, 46, 103, 0, 0, 44, 1, 45, 16, 32, 105, 108, 108, 117, 37, 143, 45, 36, 0, 109, 5, 110, 65, 33, 20, 97, 116, 32, 113, 117, 111, 17, 92, 44, 115, 32, 110, 117, 108, 108, 97, 32, 112, 97, 114, 105, 9, 165, 24, 65, 116, 32, 118, 101, 114, 111, 69, 34, 44, 101, 116, 32, 97, 99, 99, 117, 115, 97, 109, 117, 115, 1, 13, 104, 105, 117, 115, 116, 111, 32, 111, 100, 105, 111, 32, 100, 105, 103, 110, 105, 115, 115, 105, 109, 111, 115, 32, 100, 117, 99, 105, 1, 34, 80, 113, 117, 105, 32, 98, 108, 97, 110, 100, 105, 116, 105, 105, 115, 32, 112, 114, 97, 101, 115, 101, 101, 87, 17, 111, 56, 116, 117, 109, 32, 100, 101, 108, 101, 110, 105, 116, 105, 32, 97, 116, 65, 89, 28, 99, 111, 114, 114, 117, 112, 116, 105, 1, 150, 0, 115, 13, 174, 5, 109, 8, 113, 117, 97, 65, 5, 52, 108, 101, 115, 116, 105, 97, 115, 32, 101, 120, 99, 101, 112, 116, 0, 0, 0, 1, 0},
19+
largeString: {130, 83, 78, 65, 80, 80, 89, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 3, 89, 128, 8, 240, 90, 83, 101, 100, 32, 117, 116, 32, 112, 101, 114, 115, 112, 105, 99, 105, 97, 116, 105, 115, 32, 117, 110, 100, 101, 32, 111, 109, 110, 105, 115, 32, 105, 115, 116, 101, 32, 110, 97, 116, 117, 115, 32, 101, 114, 114, 111, 114, 32, 115, 105, 116, 32, 118, 111, 108, 117, 112, 116, 97, 116, 101, 109, 32, 97, 99, 99, 117, 115, 97, 110, 116, 105, 117, 109, 32, 100, 111, 108, 111, 114, 101, 109, 113, 117, 101, 32, 108, 97, 117, 100, 97, 5, 22, 240, 60, 44, 32, 116, 111, 116, 97, 109, 32, 114, 101, 109, 32, 97, 112, 101, 114, 105, 97, 109, 44, 32, 101, 97, 113, 117, 101, 32, 105, 112, 115, 97, 32, 113, 117, 97, 101, 32, 97, 98, 32, 105, 108, 108, 111, 32, 105, 110, 118, 101, 110, 116, 111, 114, 101, 32, 118, 101, 114, 105, 116, 97, 1, 141, 4, 101, 116, 1, 36, 88, 115, 105, 32, 97, 114, 99, 104, 105, 116, 101, 99, 116, 111, 32, 98, 101, 97, 116, 97, 101, 32, 118, 105, 1, 6, 120, 100, 105, 99, 116, 97, 32, 115, 117, 110, 116, 32, 101, 120, 112, 108, 105, 99, 97, 98, 111, 46, 32, 78, 101, 109, 111, 32, 101, 110, 105, 109, 5, 103, 0, 109, 46, 180, 0, 12, 113, 117, 105, 97, 17, 16, 0, 115, 5, 209, 72, 97, 115, 112, 101, 114, 110, 97, 116, 117, 114, 32, 97, 117, 116, 32, 111, 100, 105, 116, 5, 9, 36, 102, 117, 103, 105, 116, 44, 32, 115, 101, 100, 9, 53, 32, 99, 111, 110, 115, 101, 113, 117, 117, 110, 1, 42, 20, 109, 97, 103, 110, 105, 32, 9, 245, 16, 115, 32, 101, 111, 115, 1, 36, 28, 32, 114, 97, 116, 105, 111, 110, 101, 17, 96, 33, 36, 1, 51, 36, 105, 32, 110, 101, 115, 99, 105, 117, 110, 116, 1, 155, 1, 254, 16, 112, 111, 114, 114, 111, 1, 51, 36, 115, 113, 117, 97, 109, 32, 101, 115, 116, 44, 1, 14, 13, 81, 5, 183, 4, 117, 109, 1, 18, 0, 97, 9, 19, 4, 32, 115, 1, 149, 12, 109, 101, 116, 44, 9, 135, 76, 99, 116, 101, 116, 117, 114, 44, 32, 97, 100, 105, 112, 105, 115, 99, 105, 32, 118, 101, 108, 50, 173, 0, 24, 110, 111, 110, 32, 110, 117, 109, 9, 94, 84, 105, 117, 115, 32, 109, 111, 100, 105, 32, 116, 101, 109, 112, 111, 114, 97, 32, 105, 110, 99, 105, 100, 33, 52, 20, 117, 116, 32, 108, 97, 98, 33, 116, 4, 101, 116, 9, 106, 0, 101, 5, 219, 20, 97, 109, 32, 97, 108, 105, 5, 62, 33, 164, 8, 114, 97, 116, 29, 212, 12, 46, 32, 85, 116, 41, 94, 52, 97, 100, 32, 109, 105, 110, 105, 109, 97, 32, 118, 101, 110, 105, 33, 221, 72, 113, 117, 105, 115, 32, 110, 111, 115, 116, 114, 117, 109, 32, 101, 120, 101, 114, 99, 105, 33, 202, 104, 111, 110, 101, 109, 32, 117, 108, 108, 97, 109, 32, 99, 111, 114, 112, 111, 114, 105, 115, 32, 115, 117, 115, 99, 105, 112, 105, 13, 130, 8, 105, 111, 115, 1, 64, 12, 110, 105, 115, 105, 1, 150, 5, 126, 44, 105, 100, 32, 101, 120, 32, 101, 97, 32, 99, 111, 109, 5, 192, 0, 99, 41, 131, 33, 172, 8, 63, 32, 81, 1, 107, 4, 97, 117, 33, 101, 96, 118, 101, 108, 32, 101, 117, 109, 32, 105, 117, 114, 101, 32, 114, 101, 112, 114, 101, 104, 101, 110, 100, 101, 114, 105, 65, 63, 12, 105, 32, 105, 110, 1, 69, 16, 118, 111, 108, 117, 112, 65, 185, 1, 47, 24, 105, 116, 32, 101, 115, 115, 101, 1, 222, 64, 109, 32, 110, 105, 104, 105, 108, 32, 109, 111, 108, 101, 115, 116, 105, 97, 101, 46, 103, 0, 0, 44, 1, 45, 16, 32, 105, 108, 108, 117, 37, 143, 45, 36, 0, 109, 5, 110, 65, 33, 20, 97, 116, 32, 113, 117, 111, 17, 92, 44, 115, 32, 110, 117, 108, 108, 97, 32, 112, 97, 114, 105, 9, 165, 24, 65, 116, 32, 118, 101, 114, 111, 69, 34, 44, 101, 116, 32, 97, 99, 99, 117, 115, 97, 109, 117, 115, 1, 13, 104, 105, 117, 115, 116, 111, 32, 111, 100, 105, 111, 32, 100, 105, 103, 110, 105, 115, 115, 105, 109, 111, 115, 32, 100, 117, 99, 105, 1, 34, 80, 113, 117, 105, 32, 98, 108, 97, 110, 100, 105, 116, 105, 105, 115, 32, 112, 114, 97, 101, 115, 101, 101, 87, 17, 111, 56, 116, 117, 109, 32, 100, 101, 108, 101, 110, 105, 116, 105, 32, 97, 116, 65, 89, 28, 99, 111, 114, 114, 117, 112, 116, 105, 1, 150, 0, 115, 13, 174, 5, 109, 8, 113, 117, 97, 65, 5, 52, 108, 101, 115, 116, 105, 97, 115, 32, 101, 120, 99, 101, 112, 116, 0, 0, 0, 1, 0},
2020
}
2121

2222
func makeMassive(input string, numCopies int) string {
23-
outBuff := make([]byte, len(input) * numCopies)
23+
outBuff := make([]byte, len(input)*numCopies)
2424

25-
for i := 0; i < numCopies; i++ {
26-
copy(outBuff[len(outBuff):], input)
27-
}
25+
for i := 0; i < numCopies; i++ {
26+
copy(outBuff[len(outBuff):], input)
27+
}
2828

29-
return string(outBuff)
29+
return string(outBuff)
3030
}
3131

3232
func TestSnappyEncode(t *testing.T) {
@@ -39,7 +39,7 @@ func TestSnappyEncode(t *testing.T) {
3939
}
4040

4141
func TestSnappyEncodeStream(t *testing.T) {
42-
for src, _ := range snappyStreamTestCases {
42+
for src := range snappyStreamTestCases {
4343
dst := EncodeStream(nil, []byte(src))
4444

4545
// Block size can change the bytes generated, so let's just decode and make sure in matches out
@@ -195,7 +195,7 @@ func BenchmarkSnappyStreamDecodeInto(b *testing.B) {
195195
b.ResetTimer()
196196

197197
var (
198-
dst = make([]byte, 1024, 1024)
198+
dst = make([]byte, 1024)
199199
err error
200200
)
201201

@@ -236,7 +236,7 @@ func BenchmarkSnappyStreamDecodeIntoMassive(b *testing.B) {
236236
b.SetBytes(int64(len(massiveString)))
237237

238238
var (
239-
dst = make([]byte, 1024, 1024)
239+
dst = make([]byte, 1024)
240240
err error
241241
)
242242

compress/snappy/xerial_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ import (
66
"io"
77
"testing"
88

9-
goxerialsnappy "github.com/segmentio/kafka-go/compress/snappy/go-xerial-snappy"
109
"github.com/klauspost/compress/snappy"
10+
goxerialsnappy "github.com/segmentio/kafka-go/compress/snappy/go-xerial-snappy"
1111
)
1212

1313
// Wrap an io.Reader or io.Writer to disable all copy optimizations like

compression.go

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,17 +17,11 @@ const (
1717

1818
type CompressionCodec = compress.Codec
1919

20-
// TODO: this file should probably go away once the internals of the package
21-
// have moved to use the protocol package.
22-
const (
23-
compressionCodecMask = 0x07
24-
)
25-
2620
var (
2721
errUnknownCodec = errors.New("the compression code is invalid or its codec has not been imported")
2822
)
2923

30-
// resolveCodec looks up a codec by Code()
24+
// resolveCodec looks up a codec by Code().
3125
func resolveCodec(code int8) (CompressionCodec, error) {
3226
codec := compress.Compression(code).Codec()
3327
if codec == nil {

conn.go

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,7 @@ func (c *Conn) Broker() Broker {
249249
}
250250
}
251251

252-
// Controller requests kafka for the current controller and returns its URL
252+
// Controller requests kafka for the current controller and returns its URL.
253253
func (c *Conn) Controller() (broker Broker, err error) {
254254
err = c.readOperation(
255255
func(deadline time.Time, id int32) error {
@@ -276,7 +276,7 @@ func (c *Conn) Controller() (broker Broker, err error) {
276276
return broker, err
277277
}
278278

279-
// Brokers retrieve the broker list from the Kafka metadata
279+
// Brokers retrieve the broker list from the Kafka metadata.
280280
func (c *Conn) Brokers() ([]Broker, error) {
281281
var brokers []Broker
282282
err := c.readOperation(
@@ -1221,12 +1221,6 @@ func (c *Conn) SetRequiredAcks(n int) error {
12211221
}
12221222
}
12231223

1224-
func (c *Conn) writeRequestHeader(apiKey apiKey, apiVersion apiVersion, correlationID int32, size int32) {
1225-
hdr := c.requestHeader(apiKey, apiVersion, correlationID)
1226-
hdr.Size = (hdr.size() + size) - 4
1227-
hdr.writeTo(&c.wb)
1228-
}
1229-
12301224
func (c *Conn) writeRequest(apiKey apiKey, apiVersion apiVersion, correlationID int32, req request) error {
12311225
hdr := c.requestHeader(apiKey, apiVersion, correlationID)
12321226
hdr.Size = (hdr.size() + req.size()) - 4

0 commit comments

Comments
 (0)