diff --git a/device_detector.go b/device_detector.go index 11372bc..6ba0bcb 100644 --- a/device_detector.go +++ b/device_detector.go @@ -26,11 +26,11 @@ var desktopOsArray = []string{ `Chrome OS`, } -var( +var ( chrMobReg = regexp.MustCompile(fixUserAgentRegEx(`Chrome/[\.0-9]* Mobile`), regexp.IgnoreCase) chrTabReg = regexp.MustCompile(fixUserAgentRegEx(`Chrome/[\.0-9]* (?!Mobile)`), regexp.IgnoreCase) opaTabReg = regexp.MustCompile(fixUserAgentRegEx(`Opera Tablet`), regexp.IgnoreCase) - opaTvReg = regexp.MustCompile(fixUserAgentRegEx(`Opera TV Store`), regexp.IgnoreCase) + opaTvReg = regexp.MustCompile(fixUserAgentRegEx(`Opera TV Store`), regexp.IgnoreCase) ) func fixUserAgentRegEx(regex string) string { @@ -90,7 +90,6 @@ func NewDeviceDetector(dir string) (*DeviceDetector, error) { NewBot(filepath.Join(dir, FixtureFileBot)), } - return d, nil } @@ -184,7 +183,7 @@ func (d *DeviceDetector) parseInfo(info *DeviceInfo) { // If it is present the device should be a smartphone, otherwise it's a tablet // See https://developer.chrome.com/multidevice/user-agent#chrome_for_android_user_agent if deviceType == DEVICE_TYPE_INVALID && osFamily == `Android` { - if browserName,ok:=client.GetBrowserFamily(cmr.ShortName); ok&&browserName== `Chrome` { + if browserName, ok := client.GetBrowserFamily(cmr.ShortName); ok && browserName == `Chrome` { if ok, _ := chrMobReg.MatchString(ua); ok { deviceType = DEVICE_TYPE_SMARTPHONE } else if ok, _ = chrTabReg.MatchString(ua); ok { @@ -268,4 +267,3 @@ func (d *DeviceDetector) Parse(ua string) *DeviceInfo { return info } - diff --git a/device_info.go b/device_info.go index 4d09caf..86e85d1 100644 --- a/device_info.go +++ b/device_info.go @@ -17,9 +17,9 @@ var ( type DeviceInfo struct { userAgent string device.DeviceMatchResult - client *client.ClientMatchResult - os *OsMatchResult - bot *BotMatchResult + client *client.ClientMatchResult + os *OsMatchResult + bot *BotMatchResult } func (d *DeviceInfo) GetDeviceType() int { diff --git a/device_test.go b/device_test.go index 4d76548..df68e0e 100644 --- a/device_test.go +++ b/device_test.go @@ -205,4 +205,4 @@ func TestRegThread(t *testing.T) { } } wg.Wait() -} \ No newline at end of file +} diff --git a/parser/device/hbbtv.go b/parser/device/hbbtv.go index 8239a1e..aa78732 100644 --- a/parser/device/hbbtv.go +++ b/parser/device/hbbtv.go @@ -17,9 +17,12 @@ func init() { } func NewHbbTv(fileName string) *HbbTv { - h := &HbbTv{} + h := &HbbTv{ + hbbTvRegx: Regular{ + Regex: `HbbTV/([1-9]{1}(?:.[0-9]{1}){1,2})`, + }, + } if err := h.Load(fileName); err != nil { - h.hbbTvRegx.Regex = `HbbTV/([1-9]{1}(?:.[0-9]{1}){1,2})` return nil } return h