Bug-fix return -1 if not found
This commit is contained in:
@@ -73,8 +73,42 @@ func Parse(userAgent string) UserAgent {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// fmt.Println()
|
// if i, ver := tokens.getIndexValue("Android"); i != -1 {
|
||||||
// fmt.Println(tokens.list)
|
// 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
|
// OS lookup
|
||||||
switch {
|
switch {
|
||||||
@@ -127,6 +161,20 @@ func Parse(userAgent string) UserAgent {
|
|||||||
// fmt.Println(s, "--", val)
|
// 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 {
|
switch {
|
||||||
|
|
||||||
case tokens.exists("Googlebot"):
|
case tokens.exists("Googlebot"):
|
||||||
@@ -230,7 +278,7 @@ func Parse(userAgent string) UserAgent {
|
|||||||
ua.Mobile = tokens.existsAny("Mobile", "Mobile Safari")
|
ua.Mobile = tokens.existsAny("Mobile", "Mobile Safari")
|
||||||
ua.Bot = true
|
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.Name = GoogleAdsBot
|
||||||
ua.Bot = true
|
ua.Bot = true
|
||||||
ua.Mobile = ua.IsAndroid() || ua.IsIOS()
|
ua.Mobile = ua.IsAndroid() || ua.IsIOS()
|
||||||
@@ -485,7 +533,7 @@ func (p properties) getIndexValue(key string) (int, string) {
|
|||||||
return i, prop.Value
|
return i, prop.Value
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return 0, ""
|
return -1, ""
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p properties) exists(key string) bool {
|
func (p properties) exists(key string) bool {
|
||||||
|
|||||||
Reference in New Issue
Block a user