detect

package module
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 6, 2021 License: MIT Imports: 3 Imported by: 0

README

detect

Build Status License GoDoc

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

package main

import (
        "fmt"

        "github.com/h4tr3d/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!")
        }
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsMobile

func IsMobile(ua string) bool

IsMobile returns true if the visitor is using a mobile device

Types

type PlatformType

type PlatformType byte

PlatformType is the kind of platform of the device.

const (
	// Desktop operating system
	Desktop PlatformType = 1 << iota
	// Mobile operating system (android, ios, WP, ...)
	Mobile
	// Android operating system
	Android
	// IOs operating system (iPhone, iPad, iPod, ...)
	IOs
	// WindowsPhone operating system
	WindowsPhone
)

func Platform

func Platform(userAgent string) PlatformType

Platform returns the platform of the device with the given User-Agent.

func (PlatformType) String

func (i PlatformType) String() string

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL