Skip to content

Commit 3510abb

Browse files
chore: gofix
Signed-off-by: Jason Cameron <[email protected]>
1 parent 35b5e78 commit 3510abb

22 files changed

Lines changed: 59 additions & 78 deletions

File tree

cmd/anubis/main.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -418,8 +418,8 @@ func main() {
418418

419419
var redirectDomainsList []string
420420
if *redirectDomains != "" {
421-
domains := strings.Split(*redirectDomains, ",")
422-
for _, domain := range domains {
421+
domains := strings.SplitSeq(*redirectDomains, ",")
422+
for domain := range domains {
423423
_, err = url.Parse(domain)
424424
if err != nil {
425425
log.Fatalf("cannot parse redirect-domain %q: %s", domain, err.Error())

cmd/robots2policy/main.go

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010
"net/http"
1111
"os"
1212
"regexp"
13+
"slices"
1314
"strings"
1415

1516
"github.com/TecharoHQ/anubis/lib/config"
@@ -210,11 +211,8 @@ func parseRobotsTxt(input io.Reader) ([]RobotsRule, error) {
210211

211212
// Mark blacklisted user agents (those with "Disallow: /")
212213
for i := range rules {
213-
for _, disallow := range rules[i].Disallows {
214-
if disallow == "/" {
215-
rules[i].IsBlacklist = true
216-
break
217-
}
214+
if slices.Contains(rules[i].Disallows, "/") {
215+
rules[i].IsBlacklist = true
218216
}
219217
}
220218

cmd/robots2policy/robots2policy_test.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -158,8 +158,8 @@ func TestDataFileConversion(t *testing.T) {
158158
}
159159

160160
if strings.ToLower(*outputFormat) == "yaml" {
161-
var actualData []interface{}
162-
var expectedData []interface{}
161+
var actualData []any
162+
var expectedData []any
163163

164164
err = yaml.Unmarshal(actualOutput, &actualData)
165165
if err != nil {
@@ -178,8 +178,8 @@ func TestDataFileConversion(t *testing.T) {
178178
t.Errorf("Output mismatch for %s\nExpected:\n%s\n\nActual:\n%s", tc.name, expectedStr, actualStr)
179179
}
180180
} else {
181-
var actualData []interface{}
182-
var expectedData []interface{}
181+
var actualData []any
182+
var expectedData []any
183183

184184
err = json.Unmarshal(actualOutput, &actualData)
185185
if err != nil {
@@ -419,6 +419,6 @@ Disallow: /`
419419

420420
// compareData performs a deep comparison of two data structures,
421421
// ignoring differences that are semantically equivalent in YAML/JSON
422-
func compareData(actual, expected interface{}) bool {
422+
func compareData(actual, expected any) bool {
423423
return reflect.DeepEqual(actual, expected)
424424
}

internal/glob/glob.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ func Glob(pattern, subj string) bool {
3636
end := len(parts) - 1
3737

3838
// Go over the leading parts and ensure they match.
39-
for i := 0; i < end; i++ {
39+
for i := range end {
4040
idx := strings.Index(subj, parts[i])
4141

4242
switch i {

internal/hash_bench_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ func TestHashCollisions(t *testing.T) {
184184
for _, prefix := range prefixes {
185185
for _, suffix := range suffixes {
186186
for _, variation := range variations {
187-
for i := 0; i < 100; i++ {
187+
for i := range 100 {
188188
input := fmt.Sprintf("%s%s%s-%d", prefix, suffix, variation, i)
189189
hash := XXHash64sum(input)
190190
if existing, exists := xxhashHashes[hash]; exists {
@@ -211,7 +211,7 @@ func TestHashCollisions(t *testing.T) {
211211

212212
seqCount := 0
213213
for _, pattern := range patterns {
214-
for i := 0; i < 10000; i++ {
214+
for i := range 10000 {
215215
input := fmt.Sprintf(pattern, i)
216216
hash := XXHash64sum(input)
217217
if existing, exists := xxhashHashes[hash]; exists {

internal/honeypot/naive/naive.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ func (i *Impl) makeAffirmations() []string {
120120
count := rand.IntN(5) + 1
121121

122122
var result []string
123-
for j := 0; j < count; j++ {
123+
for range count {
124124
result = append(result, i.affirmation.Spin())
125125
}
126126

@@ -131,7 +131,7 @@ func (i *Impl) makeSpins() []string {
131131
count := rand.IntN(5) + 1
132132

133133
var result []string
134-
for j := 0; j < count; j++ {
134+
for range count {
135135
result = append(result, i.body.Spin())
136136
}
137137

internal/listor.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ func (lo *ListOr[T]) UnmarshalJSON(data []byte) error {
1616

1717
// Check if first non-whitespace character is '['
1818
firstChar := data[0]
19-
for i := 0; i < len(data); i++ {
19+
for i := range data {
2020
if data[i] != ' ' && data[i] != '\t' && data[i] != '\n' && data[i] != '\r' {
2121
firstChar = data[i]
2222
break
@@ -36,4 +36,4 @@ func (lo *ListOr[T]) UnmarshalJSON(data []byte) error {
3636
}
3737

3838
return nil
39-
}
39+
}

internal/ogtags/mem_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ func TestMemoryUsage(t *testing.T) {
9595

9696
// Run getTarget many times
9797
u, _ := url.Parse("/path/to/resource?query=1&foo=bar&baz=qux")
98-
for i := 0; i < 10000; i++ {
98+
for range 10000 {
9999
_ = cache.getTarget(u)
100100
}
101101

@@ -129,7 +129,7 @@ func TestMemoryUsage(t *testing.T) {
129129
runtime.GC()
130130
runtime.ReadMemStats(&m1)
131131

132-
for i := 0; i < 1000; i++ {
132+
for range 1000 {
133133
_ = cache.extractOGTags(doc)
134134
}
135135

internal/ogtags/ogtags_fuzz_test.go

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package ogtags
33
import (
44
"context"
55
"net/url"
6+
"slices"
67
"strings"
78
"testing"
89
"unicode/utf8"
@@ -78,7 +79,7 @@ func FuzzGetTarget(f *testing.F) {
7879
}
7980

8081
// Ensure no memory corruption by calling multiple times
81-
for i := 0; i < 3; i++ {
82+
for range 3 {
8283
result2 := cache.getTarget(u)
8384
if result != result2 {
8485
t.Errorf("getTarget not deterministic: %q != %q", result, result2)
@@ -148,11 +149,8 @@ func FuzzExtractOGTags(f *testing.F) {
148149
}
149150
}
150151
if !approved {
151-
for _, tag := range cache.approvedTags {
152-
if property == tag {
153-
approved = true
154-
break
155-
}
152+
if slices.Contains(cache.approvedTags, property) {
153+
approved = true
156154
}
157155
}
158156
if !approved {
@@ -260,11 +258,8 @@ func FuzzExtractMetaTagInfo(f *testing.F) {
260258
}
261259
}
262260
if !approved {
263-
for _, tag := range cache.approvedTags {
264-
if property == tag {
265-
approved = true
266-
break
267-
}
261+
if slices.Contains(cache.approvedTags, property) {
262+
approved = true
268263
}
269264
}
270265
if !approved {

internal/ogtags/parse.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package ogtags
22

33
import (
4+
"slices"
45
"strings"
56

67
"golang.org/x/net/html"
@@ -65,10 +66,8 @@ func (c *OGTagCache) extractMetaTagInfo(n *html.Node) (property, content string)
6566
}
6667

6768
// Check exact matches
68-
for _, tag := range c.approvedTags {
69-
if propertyKey == tag {
70-
return propertyKey, content
71-
}
69+
if slices.Contains(c.approvedTags, propertyKey) {
70+
return propertyKey, content
7271
}
7372

7473
return "", content

0 commit comments

Comments
 (0)