/detect

Golang library to detect the device platform given an user agent.

Primary LanguageGoMIT LicenseMIT

detect

Build Status License GoDoc

Golang library to detect the device platform given an user agent.

package main

import (
        "fmt"

        "github.com/mvader/detect"
)

func main() {
        var userAgent = "Mozilla/5.0 (iPhone; U; CPU like Mac OS X; en) AppleWebKit/420.1 (KHTML, like Gecko) Version/3.0 Mobile/4A102 Safari/419"

        platform := detect.Platform(userAgent)
        if platform == detect.Android {
                fmt.Println("Android platform detected!")
        } else {
                fmt.Printf("Platform %s detected instead :(\n", platform)
        }

        if detect.IsMobile(userAgent) {
                fmt.Println("Is mobile!")
        }
}