Bug-fix return -1 if not found
This commit is contained in:
@@ -73,8 +73,42 @@ func Parse(userAgent string) UserAgent {
|
||||
}
|
||||
}
|
||||
|
||||
// fmt.Println()
|
||||
// fmt.Println(tokens.list)
|
||||
// if i, ver := tokens.getIndexValue("Android"); i != -1 {
|
||||
// ua.OS = Android
|
||||
// ua.OSVersion = ver
|
||||
// ua.Tablet = strings.Contains(strings.ToLower(ua.String), "tablet")
|
||||
// ua.Device = tokens.findAndroidDevice(i)
|
||||
// } else if tokens.exists("iPhone") {
|
||||
// ua.OS = IOS
|
||||
// ua.OSVersion = tokens.findMacOSVersion()
|
||||
// ua.Device = "iPhone"
|
||||
// ua.Mobile = true
|
||||
// } else if tokens.exists("iPad") {
|
||||
// ua.OS = IOS
|
||||
// ua.OSVersion = tokens.findMacOSVersion()
|
||||
// ua.Device = "iPad"
|
||||
// ua.Tablet = true
|
||||
// } else if i, ver := tokens.getIndexValue("Windows NT"); i != -1 {
|
||||
// ua.OS = Windows
|
||||
// ua.OSVersion = ver
|
||||
// ua.Desktop = true
|
||||
// } else if index, ver := tokens.getIndexValue("Windows Phone OS"); index != -1 {
|
||||
// ua.OS = WindowsPhone
|
||||
// ua.OSVersion = ver
|
||||
// ua.Mobile = true
|
||||
// } else if tokens.exists("Macintosh") {
|
||||
// ua.OS = MacOS
|
||||
// ua.OSVersion = tokens.findMacOSVersion()
|
||||
// ua.Desktop = true
|
||||
// } else if i, ver := tokens.getIndexValue("Linux"); i != -1 {
|
||||
// ua.OS = Linux
|
||||
// ua.OSVersion = ver
|
||||
// ua.Desktop = true
|
||||
// } else if i, ver := tokens.getIndexValue("CrOS"); i != -1 {
|
||||
// ua.OS = ChromeOS
|
||||
// ua.OSVersion = ver
|
||||
// ua.Desktop = true
|
||||
// }
|
||||
|
||||
// OS lookup
|
||||
switch {
|
||||
@@ -127,6 +161,20 @@ func Parse(userAgent string) UserAgent {
|
||||
// fmt.Println(s, "--", val)
|
||||
// }
|
||||
|
||||
// if index, ver := tokens.getIndexValue("Googlebot"); index != -1 {
|
||||
// ua.Name = Googlebot
|
||||
// ua.Version = ver
|
||||
// ua.Bot = true
|
||||
// ua.Mobile = tokens.existsAny("Mobile", "Mobile Safari")
|
||||
|
||||
// } else if index, ver := tokens.getIndexValue("Applebot"); index != -1 {
|
||||
// ua.Name = Applebot
|
||||
// ua.Version = ver
|
||||
// ua.Bot = true
|
||||
// ua.Mobile = tokens.existsAny("Mobile", "Mobile Safari")
|
||||
// ua.OS = ""
|
||||
// }
|
||||
|
||||
switch {
|
||||
|
||||
case tokens.exists("Googlebot"):
|
||||
@@ -230,7 +278,7 @@ func Parse(userAgent string) UserAgent {
|
||||
ua.Mobile = tokens.existsAny("Mobile", "Mobile Safari")
|
||||
ua.Bot = true
|
||||
|
||||
case tokens.exists("AdsBot-Google-Mobile") || tokens.exists("Mediapartners-Google") || tokens.exists("AdsBot-Google"):
|
||||
case tokens.existsAny("AdsBot-Google-Mobile", "Mediapartners-Google", "AdsBot-Google"):
|
||||
ua.Name = GoogleAdsBot
|
||||
ua.Bot = true
|
||||
ua.Mobile = ua.IsAndroid() || ua.IsIOS()
|
||||
@@ -485,7 +533,7 @@ func (p properties) getIndexValue(key string) (int, string) {
|
||||
return i, prop.Value
|
||||
}
|
||||
}
|
||||
return 0, ""
|
||||
return -1, ""
|
||||
}
|
||||
|
||||
func (p properties) exists(key string) bool {
|
||||
|
||||
Reference in New Issue
Block a user