File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff 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"
2829 tableColorBold = tablewriter.Colors {tablewriter .Bold }
2930)
3031
32+ type UAKeyType = unique.Handle [string ]
33+
3134type 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
5053func (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
You can’t perform that action at this time.
0 commit comments