Created
August 6, 2015 18:52
-
-
Save Philio/147427db9645a0601632 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"fmt" | |
"time" | |
bgo "github.com/fromYukki/browscap_go" | |
) | |
func main() { | |
start := time.Now().UnixNano() | |
if err := bgo.InitBrowsCap("browscap.ini", false); err != nil { | |
panic(err) | |
} | |
fmt.Printf("Time to load browscap.ini: %dns\n", time.Now().UnixNano() - start) | |
lookupStart := time.Now().UnixNano() | |
browser, ok := bgo.GetBrowser("Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/37.0.2062.120 Safari/537.36") | |
if !ok || browser == nil { | |
panic("Browser not found") | |
} else { | |
fmt.Printf("Browser = %s [%s] v%s\n", browser.Browser, browser.BrowserType, browser.BrowserVersion) | |
fmt.Printf("Platform = %s v%s\n", browser.Platform, browser.PlatformVersion) | |
fmt.Printf("Device = %s [%s] %s\n", browser.DeviceName, browser.DeviceType, browser.DeviceBrand) | |
fmt.Printf("IsCrawler = %t\n", browser.IsCrawler()) | |
fmt.Printf("IsMobile = %t\n", browser.IsMobile()) | |
} | |
fmt.Printf("Time to do lookup: %dns\n", time.Now().UnixNano() - lookupStart) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment