Categorygithub.com/mvader/detect
modulepackage
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!")
        }
}

# Functions

IsMobile returns true if the visitor is using a mobile device.
Platform returns the platform of the device with the given User-Agent.

# Constants

Android operating system.
Desktop operating system.
IOs operating system (iPhone, iPad, iPod, ...).
Mobile operating system (android, ios, WP, ...).
WindowsPhone operating system.

# Type aliases

PlatformType is the kind of platform of the device.