Categorygithub.com/mvader/detect
repositorypackage
0.0.0-20160524092137-c0c2ff5e5733
Repository: https://github.com/mvader/detect.git
Documentation: pkg.go.dev

# README

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