Skip to content

Commit fc18bdf

Browse files
authored
Merge pull request #61 from Gsantomaggio/zerpet/staticcheck-warnings
Fix staticcheck errors
2 parents cf6ab7f + dc24c7f commit fc18bdf

File tree

13 files changed

+74
-44
lines changed

13 files changed

+74
-44
lines changed

.github/workflows/build_test_linux.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,13 @@ on:
1010
branches: [ "main" ]
1111

1212
jobs:
13-
1413
build:
1514
runs-on: ubuntu-latest
1615
steps:
1716
- uses: actions/checkout@v3
1817

1918
- name: Set up Go
20-
uses: actions/setup-go@v3
19+
uses: actions/setup-go@v4
2120
with:
2221
go-version: oldstable
2322

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
2+
name: "Static Check Analysis"
3+
4+
on: ["pull_request"]
5+
6+
jobs:
7+
static-check:
8+
runs-on: ubuntu-latest
9+
steps:
10+
- uses: actions/checkout@v3
11+
with:
12+
fetch-depth: 1
13+
14+
- name: Set up Go
15+
uses: actions/setup-go@v4
16+
with:
17+
go-version: 'stable'
18+
19+
- name: Staticcheck
20+
uses: dominikh/staticcheck-action@v1.3.0
21+
with:
22+
version: "2023.1.3"
23+
install-go: false
24+
build-tags: "rabbitmq.stream.test,rabbitmq.stream.e2e"

go.mod

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
module github.com/gsantomaggio/rabbitmq-stream-go-client
22

3-
go 1.19
3+
go 1.20
44

55
require (
66
github.com/golang/mock v1.6.0
@@ -13,7 +13,7 @@ require (
1313
github.com/go-logr/logr v1.2.3 // indirect
1414
github.com/google/go-cmp v0.5.9 // indirect
1515
golang.org/x/net v0.2.0 // indirect
16-
golang.org/x/sys v0.2.0 // indirect
16+
golang.org/x/sys v0.7.0 // indirect
1717
golang.org/x/text v0.4.0 // indirect
1818
gopkg.in/yaml.v3 v3.0.1 // indirect
1919
)

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@ golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7w
2727
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
2828
golang.org/x/sys v0.0.0-20210330210617-4fbd30eecc44/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
2929
golang.org/x/sys v0.0.0-20210510120138-977fb7262007/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
30-
golang.org/x/sys v0.2.0 h1:ljd4t30dBnAvMZaQCevtY0xLLD0A+bRZXbgLMLU1F/A=
31-
golang.org/x/sys v0.2.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
30+
golang.org/x/sys v0.7.0 h1:3jlCCIQZPdOYu1h8BkNvLz8Kgwtae2cagcG/VamtZRU=
31+
golang.org/x/sys v0.7.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
3232
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
3333
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
3434
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=

internal/exchange_command_versions.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -117,9 +117,7 @@ type ExchangeCommandVersionsResponse struct {
117117

118118
func NewExchangeCommandVersionsResponse(id uint32, responseCode uint16, commands ...commandInformer) *ExchangeCommandVersionsResponse {
119119
e := &ExchangeCommandVersionsResponse{correlationId: id, responseCode: responseCode}
120-
for _, c := range commands {
121-
e.commands = append(e.commands, c)
122-
}
120+
e.commands = append(e.commands, commands...)
123121
return e
124122
}
125123

internal/open.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,9 +71,12 @@ func (o *OpenResponse) MarshalBinary() (data []byte, err error) {
7171
return nil, fmt.Errorf("error in binary marshal: wrote %d expected %d", n, 6)
7272
}
7373

74-
if o.connectionProperties != nil && len(o.connectionProperties) > 0 {
74+
if len(o.connectionProperties) > 0 {
7575
// FIXME: check how many bytes were written
7676
_, err = writeMany(wr, o.connectionProperties)
77+
if err != nil {
78+
return nil, err
79+
}
7780
}
7881

7982
err = wr.Flush()

internal/sasl_mechanisms.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,9 @@ func (s *SaslHandshakeResponse) MarshalBinary() (data []byte, err error) {
6666

6767
for _, mechanism := range s.Mechanisms {
6868
n, err = writeString(wr, mechanism)
69+
if err != nil {
70+
return nil, err
71+
}
6972
if n != (len(mechanism) + 2) {
7073
return nil, fmt.Errorf("error marshalling: wrote %d, expected %d", n, len(mechanism)+2)
7174
}

internal/wire_formatting.go

Lines changed: 14 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package internal
22

33
import (
4-
"bufio"
54
"encoding/binary"
65
"io"
76
)
@@ -18,14 +17,6 @@ func readUInt(readerStream io.Reader) (uint32, error) {
1817
return res, err
1918
}
2019

21-
func peekByte(readerStream *bufio.Reader) (uint8, error) {
22-
res, err := readerStream.Peek(1)
23-
if err != nil {
24-
return 0, err
25-
}
26-
return res[0], nil
27-
}
28-
2920
func readString(readerStream io.Reader) string {
3021
// FIXME: handle the potential error from readUShort
3122
lenString, _ := readUShort(readerStream)
@@ -67,23 +58,21 @@ func readMany(readerStream io.Reader, args ...interface{}) error {
6758

6859
func readAny(readerStream io.Reader, arg interface{}) error {
6960

70-
switch arg.(type) {
61+
switch arg := arg.(type) {
7162
case *int:
7263
uInt, err := readUInt(readerStream)
7364
if err != nil {
7465
return err
7566
}
76-
*arg.(*int) = int(uInt)
77-
break
67+
*arg = int(uInt)
7868
case *string:
79-
*arg.(*string) = readString(readerStream)
80-
break
69+
*arg = readString(readerStream)
8170
case *[]byte:
8271
byteSlice, err := readByteSlice(readerStream)
8372
if err != nil {
8473
return err
8574
}
86-
*arg.(*[]byte) = byteSlice
75+
*arg = byteSlice
8776
case *map[string]string:
8877
mapLen, err := readUInt(readerStream)
8978
if err != nil {
@@ -95,7 +84,7 @@ func readAny(readerStream io.Reader, arg interface{}) error {
9584
v := readString(readerStream)
9685
myMap[k] = v
9786
}
98-
*arg.(*map[string]string) = myMap
87+
*arg = myMap
9988
default:
10089
err := binary.Read(readerStream, binary.BigEndian, arg)
10190
if err != nil {
@@ -113,31 +102,31 @@ func writeMany(writer io.Writer, args ...any) (int, error) {
113102
var written int
114103

115104
for _, arg := range args {
116-
switch arg.(type) {
105+
switch arg := arg.(type) {
117106
case int:
118-
err := binary.Write(writer, binary.BigEndian, int32(arg.(int)))
107+
err := binary.Write(writer, binary.BigEndian, int32(arg))
119108
if err != nil {
120109
return written, err
121110
}
122-
written += binary.Size(int32(arg.(int)))
123-
break
111+
written += binary.Size(int32(arg))
124112
case string:
125-
n, err := writeString(writer, arg.(string))
113+
n, err := writeString(writer, arg)
126114
if err != nil {
127115
return written, err
128116
}
129117
written += n
130-
break
131118
case map[string]string:
132-
m := arg.(map[string]string)
133-
n, err := writeMany(writer, len(m))
119+
n, err := writeMany(writer, len(arg))
134120
if err != nil {
135121
return n, err
136122
}
137123
written += n
138-
for key, value := range m {
124+
for key, value := range arg {
139125
n, err := writeString(writer, key)
140126
written += n
127+
if err != nil {
128+
return n, err
129+
}
141130
n, err = writeString(writer, value)
142131
written += n
143132
if err != nil {

main.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,6 @@ func main() {
6161
if (confirmed % totalMessages) == 0 {
6262
log.Info("Confirmed", "messages", confirmed)
6363
}
64-
break
6564
case 2:
6665
confirmed += len(c.PublishingIds())
6766
log.Info("Sub Entry Send Confirmed", "messages", confirmed)
@@ -112,6 +111,9 @@ func main() {
112111
}()
113112

114113
err = streamClient.Subscribe(ctx, stream, constants.OffsetTypeFirst, 1, 10, map[string]string{"name": "my_consumer"}, 10)
114+
if err != nil {
115+
panic(err)
116+
}
115117

116118
offset, err := streamClient.QueryOffset(ctx, "my_consumer", stream)
117119
if err != nil {

pkg/e2e/end_to_end_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ var _ = Describe("E2E", Serial, Label("e2e"), func() {
117117
})
118118

119119
func wrap[T any](v T) []T {
120-
r := make([]T, 1, 1)
120+
r := make([]T, 1)
121121
r[0] = v
122122
return r
123123
}

0 commit comments

Comments
 (0)