Skip to content

Commit eb8645b

Browse files
chore: modernize loop in IsIPv4
Signed-off-by: Artur Melanchyk <13834276+arturmelanchyk@users.noreply.github.com>
1 parent 9ea03e1 commit eb8645b

2 files changed

Lines changed: 3 additions & 3 deletions

File tree

ips.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import (
88
// but without check for IPv6 case and without returning net.IP slice, whereby IsIPv4 makes no allocations.
99
func IsIPv4(s string) bool {
1010
//nolint:modernize-loop // old way is more readable
11-
for i := 0; i < net.IPv4len; i++ {
11+
for i := range net.IPv4len {
1212
if len(s) == 0 {
1313
return false
1414
}

ips_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ func Test_IPWhitespace(t *testing.T) {
101101
require.False(t, IsIPv6("::1 "))
102102
}
103103

104-
// go test -v -run=^$ -bench=UnsafeString -benchmem -count=2
104+
// go test -v -run=^$ -bench=Benchmark_IsIPv4 -benchmem -count=6
105105
func Benchmark_IsIPv4(b *testing.B) {
106106
ip := "174.23.33.100"
107107
var res bool
@@ -121,7 +121,7 @@ func Benchmark_IsIPv4(b *testing.B) {
121121
})
122122
}
123123

124-
// go test -v -run=^$ -bench=UnsafeString -benchmem -count=2
124+
// go test -v -run=^$ -bench=Benchmark_IsIPv6 -benchmem -count=6
125125
func Benchmark_IsIPv6(b *testing.B) {
126126
ip := "9396:9549:b4f7:8ed0:4791:1330:8c06:e62d"
127127
var res bool

0 commit comments

Comments
 (0)