更新UserAgent分析库
This commit is contained in:
@@ -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,
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user