Skip to content

Commit 8721739

Browse files
committed
analyze: Use unique.Handle for UA
1 parent bba3e1e commit 8721739

1 file changed

Lines changed: 6 additions & 7 deletions

File tree

pkg/analyze/analyze.go

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import (
1212
"strconv"
1313
"sync"
1414
"time"
15+
"unique"
1516

1617
"github.com/cakturk/go-netstat/netstat"
1718
"github.com/dustin/go-humanize"
@@ -28,6 +29,8 @@ var (
2829
tableColorBold = tablewriter.Colors{tablewriter.Bold}
2930
)
3031

32+
type UAKeyType = unique.Handle[string]
33+
3134
type IPStats struct {
3235
Size uint64
3336
Requests uint64
@@ -44,7 +47,7 @@ type IPStats struct {
4447
LastURLAccess time.Time
4548

4649
// User-agent
47-
UAStore map[string]struct{}
50+
UAStore map[UAKeyType]struct{}
4851
}
4952

5053
func (i IPStats) UpdateWith(item parser.LogItem) IPStats {
@@ -62,13 +65,9 @@ func (i IPStats) UpdateWith(item parser.LogItem) IPStats {
6265
}
6366
}
6467
if i.UAStore == nil {
65-
i.UAStore = make(map[string]struct{})
66-
}
67-
if len(item.Useragent) <= 50 {
68-
i.UAStore[item.Useragent] = struct{}{}
69-
} else {
70-
i.UAStore[item.Useragent[:50]] = struct{}{}
68+
i.UAStore = make(map[UAKeyType]struct{})
7169
}
70+
i.UAStore[unique.Make(item.Useragent)] = struct{}{}
7271
return i
7372
}
7473

0 commit comments

Comments
 (0)