初始化
()
| 49 | |
| 50 | // 初始化 |
| 51 | func (this *UserAgentParser) init() { |
| 52 | var maxCacheItems = 10_000 |
| 53 | var systemMemory = memutils.SystemMemoryGB() |
| 54 | if systemMemory >= 16 { |
| 55 | maxCacheItems = 40_000 |
| 56 | } else if systemMemory >= 8 { |
| 57 | maxCacheItems = 30_000 |
| 58 | } else if systemMemory >= 4 { |
| 59 | maxCacheItems = 20_000 |
| 60 | } |
| 61 | this.maxCacheItems = maxCacheItems |
| 62 | |
| 63 | this.gcTicker = time.NewTicker(5 * time.Second) |
| 64 | goman.New(func() { |
| 65 | for range this.gcTicker.C { |
| 66 | this.GC() |
| 67 | } |
| 68 | }) |
| 69 | } |
| 70 | |
| 71 | // Parse 解析UserAgent |
| 72 | func (this *UserAgentParser) Parse(userAgent string) (result UserAgentParserResult) { |
no test coverage detected