Skip to content

Commit ec0d519

Browse files
committed
all: lint fixes
- use newer build constraint format - run go fmt ./... - fix uses of deprecated ioutil package - don't shadow builtin identifier "max" - ovsdb/internal/jsonrpc: ignore gosec rule G102 for test helper
1 parent b54fb29 commit ec0d519

File tree

11 files changed

+28
-27
lines changed

11 files changed

+28
-27
lines changed

ovs/action.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -456,7 +456,7 @@ func (a *outputFieldAction) GoString() string {
456456
// applies multipath link selection `algorithm` (with parameter `arg`)
457457
// to choose one of `n_links` output links numbered 0 through n_links
458458
// minus 1, and stores the link into `dst`, which must be a field or
459-
// subfield in the syntax described under ``Field Specifications’’
459+
// subfield in the syntax described under Field Specifications’’
460460
// above.
461461
// https://www.openvswitch.org/support/dist-docs/ovs-actions.7.txt
462462
func Multipath(fields string, basis int, algorithm string, nlinks int, arg int, dst string) Action {

ovs/client.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ import (
1818
"bytes"
1919
"fmt"
2020
"io"
21-
"io/ioutil"
2221
"log"
2322
"os/exec"
2423
"strings"
@@ -145,7 +144,7 @@ func shellPipe(stdin io.Reader, cmd string, args ...string) ([]byte, error) {
145144
}
146145

147146
mr := io.MultiReader(stdout, stderr)
148-
b, err := ioutil.ReadAll(mr)
147+
b, err := io.ReadAll(mr)
149148
if err != nil {
150149
return nil, err
151150
}

ovs/datapath_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,7 @@ func TestGetCTLimits(t *testing.T) {
265265
}
266266
case handleError:
267267
if err != nil && err.Error() != tt.err {
268-
t.Errorf(err.Error())
268+
t.Error(err.Error())
269269
}
270270
default:
271271
t.Log("pass")
@@ -346,7 +346,7 @@ func TestGetCTLimitsWithBinary(t *testing.T) {
346346
}
347347
case handleError:
348348
if err != nil && err.Error() != tt.err {
349-
t.Errorf(err.Error())
349+
t.Error(err.Error())
350350
}
351351

352352
default:
@@ -426,7 +426,7 @@ func TestCtSetLimitsArgsToString(t *testing.T) {
426426
got, err := ctSetLimitsArgsToString(tt.zone)
427427
if err != nil {
428428
if err.Error() != tt.err {
429-
t.Errorf(err.Error())
429+
t.Error(err.Error())
430430
}
431431
}
432432
if got != tt.want1 && got != tt.want2 {

ovs/matchparser.go

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -116,23 +116,23 @@ func parseMatch(key string, value string) (Match, error) {
116116
}
117117

118118
// parseClampInt calls strconv.Atoi on s, and then ensures that s is less than
119-
// or equal to the integer specified by max.
120-
func parseClampInt(s string, max int) (int, error) {
119+
// or equal to the integer specified by upper.
120+
func parseClampInt(s string, upper int) (int, error) {
121121
t, err := strconv.Atoi(s)
122122
if err != nil {
123123
return 0, err
124124
}
125-
if t > max {
126-
return 0, fmt.Errorf("integer %d too large; %d > %d", t, t, max)
125+
if t > upper {
126+
return 0, fmt.Errorf("integer %d too large; %d > %d", t, t, upper)
127127
}
128128

129129
return t, nil
130130
}
131131

132132
// parseIntMatch parses an integer Match value from the input key and value,
133-
// with a maximum possible value of max.
134-
func parseIntMatch(key string, value string, max int) (Match, error) {
135-
t, err := parseClampInt(value, max)
133+
// with a maximum possible value of upper.
134+
func parseIntMatch(key string, value string, upper int) (Match, error) {
135+
t, err := parseClampInt(value, upper)
136136
if err != nil {
137137
return nil, err
138138
}
@@ -176,8 +176,8 @@ func parseIntMatch(key string, value string, max int) (Match, error) {
176176
}
177177

178178
// parsePort parses a port or port/mask Match value from the input key and value,
179-
// with a maximum possible value of max.
180-
func parsePort(key string, value string, max int) (Match, error) {
179+
// with a maximum possible value of upper.
180+
func parsePort(key string, value string, upper int) (Match, error) {
181181

182182
var values []uint64
183183
//Split the string
@@ -186,7 +186,7 @@ func parsePort(key string, value string, max int) (Match, error) {
186186
//If input is just port
187187
switch len(ss) {
188188
case 1:
189-
val, err := parseClampInt(value, max)
189+
val, err := parseClampInt(value, upper)
190190
if err != nil {
191191
return nil, err
192192
}
@@ -200,8 +200,8 @@ func parsePort(key string, value string, max int) (Match, error) {
200200
return nil, err
201201
}
202202
// Return error if val > 65536 (uint16)
203-
if val > uint64(max) {
204-
return nil, fmt.Errorf("integer %d too large; %d > %d", val, val, max)
203+
if val > uint64(upper) {
204+
return nil, fmt.Errorf("integer %d too large; %d > %d", val, val, upper)
205205
}
206206

207207
values = append(values, val)

ovs/portstats.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,9 @@ type PortStatsTransmit struct {
6464

6565
// UnmarshalText unmarshals a PortStats from textual form as output by
6666
// 'ovs-ofctl dump-ports':
67-
// port 1: rx pkts=0, bytes=0, drop=0, errs=0, frame=0, over=0, crc=0
68-
// tx pkts=0, bytes=0, drop=0, errs=0, coll=0
67+
//
68+
// port 1: rx pkts=0, bytes=0, drop=0, errs=0, frame=0, over=0, crc=0
69+
// tx pkts=0, bytes=0, drop=0, errs=0, coll=0
6970
func (p *PortStats) UnmarshalText(b []byte) error {
7071
// Make a copy per documentation for encoding.TextUnmarshaler.
7172
s := string(b)

ovs/table.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,9 @@ type Table struct {
3939

4040
// UnmarshalText unmarshals a Table from textual form as output by
4141
// 'ovs-ofctl dump-tables':
42-
// 0: classifier: wild=0x3fffff, max=1000000, active=0
43-
// lookup=0, matched=0
42+
//
43+
// 0: classifier: wild=0x3fffff, max=1000000, active=0
44+
// lookup=0, matched=0
4445
func (t *Table) UnmarshalText(b []byte) error {
4546
// Make a copy per documentation for encoding.TextUnmarshaler.
4647
s := string(b)

ovsdb/internal/jsonrpc/testconn.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ func TestConn(t *testing.T, fn TestFunc) (*Conn, chan<- *Response, func()) {
5151
func TestNetConn(t *testing.T, fn TestFunc) (net.Conn, chan<- *Response, func()) {
5252
t.Helper()
5353

54-
l, err := net.Listen("tcp", ":0")
54+
l, err := net.Listen("tcp", ":0") // #nosec G102
5555
if err != nil {
5656
t.Fatalf("failed to listen: %v", err)
5757
}

ovsnl/client_linux_integration_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15-
//+build linux
15+
//go:build linux
1616

1717
package ovsnl_test
1818

ovsnl/client_linux_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15-
//+build linux
15+
//go:build linux
1616

1717
package ovsnl
1818

ovsnl/datapath_linux_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15-
//+build linux
15+
//go:build linux
1616

1717
package ovsnl
1818

0 commit comments

Comments
 (0)