gmzhang / detect

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

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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!")
        }
}

About

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

License:MIT License


Languages

Language:Go 100.0%