更新UserAgent分析库

This commit is contained in:
GoEdgeLab
2023-05-20 11:52:27 +08:00
parent 4e77bbc784
commit a1ac83d526
5 changed files with 21 additions and 15 deletions

View File

@@ -5,7 +5,7 @@ package stats
import (
"github.com/TeaOSLab/EdgeNode/internal/utils"
"github.com/TeaOSLab/EdgeNode/internal/utils/fnv"
"github.com/mssola/user_agent"
"github.com/mssola/useragent"
"sync"
)
@@ -13,7 +13,7 @@ var SharedUserAgentParser = NewUserAgentParser()
// UserAgentParser UserAgent解析器
type UserAgentParser struct {
parser *user_agent.UserAgent
parser *useragent.UserAgent
cacheMap1 map[uint64]UserAgentParserResult
cacheMap2 map[uint64]UserAgentParserResult
@@ -25,7 +25,7 @@ type UserAgentParser struct {
func NewUserAgentParser() *UserAgentParser {
var parser = &UserAgentParser{
parser: &user_agent.UserAgent{},
parser: &useragent.UserAgent{},
cacheMap1: map[uint64]UserAgentParserResult{},
cacheMap2: map[uint64]UserAgentParserResult{},
cacheCursor: 0,

View File

@@ -2,10 +2,12 @@
package stats
import "github.com/mssola/user_agent"
import (
"github.com/mssola/useragent"
)
type UserAgentParserResult struct {
OS user_agent.OSInfo
OS useragent.OSInfo
BrowserName string
BrowserVersion string
IsMobile bool

View File

@@ -12,7 +12,7 @@ import (
func TestUserAgentParser_Parse(t *testing.T) {
var parser = NewUserAgentParser()
for i := 0; i < 4; i ++ {
for i := 0; i < 4; i++ {
t.Log(parser.Parse("Mozilla/5.0 (Windows NT 10.0; WOW64; rv:49.0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/88.0.4324.96 Safari/537.36 Test/1"))
t.Log(parser.Parse("Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.110 Safari/537.36"))
}
@@ -59,3 +59,13 @@ func BenchmarkUserAgentParser_Parse2(b *testing.B) {
}
b.Log(len(parser.cacheMap1), len(parser.cacheMap2))
}
func BenchmarkUserAgentParser_Parse3(b *testing.B) {
var parser = NewUserAgentParser()
b.RunParallel(func(pb *testing.PB) {
for pb.Next() {
parser.Parse("Mozilla/5.0 (Windows NT 10.0; WOW64; rv:49.0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/88.0.4324.96 Safari/537.36 Test/" + types.String(rands.Int(0, 100_000)))
}
})
b.Log(len(parser.cacheMap1), len(parser.cacheMap2))
}