mobiledetect

package module
v0.0.0-...-25f014f Latest Latest
Warning

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

Go to latest
Published: Dec 11, 2017 License: MIT Imports: 5 Imported by: 28

README

GoMobileDetect

GoDoc Build Status Coverage Status

Description

GoMobileDetect is a lightweight package imported from PHP for detecting mobile devices including tablets.

The package is imported from MobileDetect which was originally written in PHP.

Installation
$ go get github.com/Shaked/gomobiledetect 
Updates
Version 1.2.0
  • Now supports using Http.Handler implementation. See examples
Version 1.0.0
  • The package name had been changed to mobiledetect.
Version 0.2.0
  • This version introduces a new method IsKey(key int). This method is faster than the Is(key string). All keys can be found here

  • The Is(key string) has been changed to support both string and int using the interface{}.

Benchmarking
Version 0.1.2
BenchmarkIsMobile       2000       1001884 ns/op
ok      github.com/Shaked/gomobiledetect    7.091s
Version 0.2.0
BenchmarkIsMobile     100000         19278 ns/op
ok      github.com/Shaked/gomobiledetect    7.448s
Usage

There are different ways of using the package:

License

Go Mobile Detect is an open-source script released under MIT License.

Documentation

Overview

Gomobiledetect is a lightweight Go package imported from PHP for detecting mobile devices (including tablets). It uses the User-Agent string combined with specific HTTP headers to detect the mobile environment

Index

Constants

View Source
const (
	MOBILE_GRADE_A = "A"
	MOBILE_GRADE_B = "B"
	MOBILE_GRADE_C = "C"
)
View Source
const (
	PROP_MOBILE = iota
	PROP_BUILD
	PROP_VERSION
	PROP_VENDORID
	PROP_IPAD
	PROP_IPHONE
	PROP_IPOD
	PROP_KINDLE
	PROP_CHROME
	PROP_COAST
	PROP_DOLFIN
	PROP_FIREFOX
	PROP_FENNEC
	PROP_IE
	PROP_NETFRONT
	PROP_NOKIABROWSER
	PROP_OPERA
	PROP_OPERA_MINI
	PROP_OPERA_MOBI
	PROP_UC_BROWSER
	PROP_MQQBROWSER
	PROP_MICROMESSENGER
	PROP_BAIDUBOXAPP
	PROP_BAIDUBROWSER
	PROP_SAFARI
	PROP_SKYFIRE
	PROP_TIZEN
	PROP_WEBKIT
	PROP_GECKO
	PROP_TRIDENT
	PROP_PRESTO
	PROP_IOS
	PROP_ANDROID
	PROP_BLACKBERRY
	PROP_BREW
	PROP_JAVA
	PROP_WINDOWS_PHONE_OS
	PROP_WINDOWS_PHONE
	PROP_WINDOWS_CE
	PROP_WINDOWS_NT
	PROP_SYMBIAN
	PROP_WEBOS
)
View Source
const (
	IPHONE = iota
	BLACKBERRY
	HTC
	NEXUS
	DELL
	MOTOROLA
	SAMSUNG
	LG
	SONY
	ASUS
	NOKIA
	MICROMAX
	PALM
	VERTU
	PANTECH
	FLY
	WIKO
	IMOBILE
	SIMVALLEY
	WOLFGANG
	ALCATEL
	NINTENDO
	AMOI
	INQ
	GENERICPHONE

	IPAD = iota
	NEXUSTABLET
	SAMSUNGTABLET
	KINDLE
	SURFACETABLET
	HPTABLET
	ASUSTABLET
	BLACKBERRYTABLET
	HTCTABLET
	MOTOROLATABLET
	NOOKTABLET
	ACERTABLET
	TOSHIBATABLET
	LGTABLET
	FUJITSUTABLET
	PRESTIGIOTABLET
	LENOVOTABLET
	DELLTABLET
	YARVIKTABLET
	MEDIONTABLET
	ARNOVATABLET
	INTENSOTABLET
	IRUTABLET
	MEGAFONTABLET
	EBODATABLET
	ALLVIEWTABLET
	ARCHOSTABLET
	AINOLTABLET
	NOKIALUMIATABLET
	SONYTABLET
	PHILIPSTABLET
	CUBETABLET
	COBYTABLET
	MIDTABLET
	MSITABLET
	SMITTABLET
	ROCKCHIPTABLET
	FLYTABLET
	BQTABLET
	HUAWEITABLET
	NECTABLET
	PANTECHTABLET
	BRONCHOTABLET
	VERSUSTABLET
	ZYNCTABLET
	POSITIVOTABLET
	NABITABLET
	KOBOTABLET
	DANEWTABLET
	TEXETTABLET
	PLAYSTATIONTABLET
	TREKSTORTABLET
	PYLEAUDIOTABLET
	ADVANTABLET
	DANYTECHTABLET
	GALAPADTABLET
	MICROMAXTABLET
	KARBONNTABLET
	ALLFINETABLET
	PROSCANTABLET
	YONESTABLET
	CHANGJIATABLET
	GUTABLET
	POINTOFVIEWTABLET
	OVERMAXTABLET
	HCLTABLET
	DPSTABLET
	VISTURETABLET
	CRESTATABLET
	MEDIATEKTABLET
	CONCORDETABLET
	GOCLEVERTABLET
	MODECOMTABLET
	VONINOTABLET
	ECSTABLET
	STOREXTABLET
	VODAFONETABLET
	ESSENTIELBTABLET
	ROSSMOORTABLET
	IMOBILETABLET
	TOLINOTABLET
	AUDIOSONICTABLET
	AMPETABLET
	SKKTABLET
	TECNOTABLET
	JXDTABLET
	IJOYTABLET
	FX2TABLET
	XOROTABLET
	VIEWSONICTABLET
	VERIZONTABLET
	ODYSTABLET
	CAPTIVATABLET
	ICONBITTABLET
	TECLASTTABLET
	ONDATABLET
	JAYTECHTABLET
	BLAUPUNKTTABLET
	DIGMATABLET
	EVOLIOTABLET
	LAVATABLET
	AOCTABLET
	MPMANTABLET
	CELKONTABLET
	WOLDERTABLET
	MITABLET
	NIBIRUTABLET
	NEXOTABLET
	LEADERTABLET
	UBISLATETABLET
	POCKETBOOKTABLET
	KOCASOTABLET
	HISENSETABLET
	HUDL
	TELSTRATABLET
	GENERICTABLET

	ANDROIDOS = iota
	BLACKBERRYOS
	PALMOS
	SYMBIANOS
	WINDOWSMOBILEOS
	WINDOWSPHONEOS
	IOS
	MEEGOOS
	MAEMOOS
	JAVAOS
	WEBOS
	BADAOS
	BREWOS

	CHROME = iota
	DOLFIN
	OPERA
	SKYFIRE
	EDGE
	IE
	FIREFOX
	BOLT
	TEASHARK
	BLAZER
	SAFARI
	TIZEN
	UCBROWSER
	BAIDUBOXAPP
	BAIDUBROWSER
	DIIGOBROWSER
	PUFFIN
	MERCURY
	OBIGOBROWSER
	NETFRONT
	GENERICBROWSER
	PALEMOON
)

Variables

This section is empty.

Functions

func Device

func Device(r *http.Request) string

Vars returns the route variables for the current request, if any.

func Handler

func Handler(h DeviceHandler, rules *rules) http.Handler

func HandlerMux

func HandlerMux(s *http.ServeMux, rules *rules) http.Handler

func NewRules

func NewRules() *rules

NewRules creates a object with all rules necessary to figure out a browser from a User Agent string

Types

type DeviceHandler

type DeviceHandler interface {
	Mobile(w http.ResponseWriter, r *http.Request, m *MobileDetect)
	Tablet(w http.ResponseWriter, r *http.Request, m *MobileDetect)
	Desktop(w http.ResponseWriter, r *http.Request, m *MobileDetect)
}

type MobileDetect

type MobileDetect struct {
	// contains filtered or unexported fields
}

MobileDetect holds the structure to figure out a browser from a UserAgent string and methods necessary to make it happen

func NewMobileDetect

func NewMobileDetect(r *http.Request, rules *rules) *MobileDetect

NewMobileDetect creates the MobileDetect object

func (*MobileDetect) CheckHttpHeadersForMobile

func (md *MobileDetect) CheckHttpHeadersForMobile() bool

CheckHttpHeadersForMobile looks for mobile rules to confirm if the browser is a mobile browser

func (*MobileDetect) Is

func (md *MobileDetect) Is(key interface{}) bool

It is recommended to use IsKey instead

func (*MobileDetect) IsKey

func (md *MobileDetect) IsKey(key int) bool

Is compared the detected browser with a "rule" from the existing rules list

func (*MobileDetect) IsMobile

func (md *MobileDetect) IsMobile() bool

IsMobile is a specific case to detect only mobile browsers.

func (*MobileDetect) IsTablet

func (md *MobileDetect) IsTablet() bool

IsMobile is a specific case to detect only mobile browsers on tablets. Do not overlap with IsMobile

func (*MobileDetect) MobileGrade

func (md *MobileDetect) MobileGrade() string

MobileGrade returns a graduation similar to jQuery's Graded Browse Support

func (*MobileDetect) PreCompileRegexRules

func (md *MobileDetect) PreCompileRegexRules() *MobileDetect

func (*MobileDetect) SetHttpHeaders

func (md *MobileDetect) SetHttpHeaders(httpHeaders map[string]string) *MobileDetect

func (*MobileDetect) SetUserAgent

func (md *MobileDetect) SetUserAgent(userAgent string) *MobileDetect

func (*MobileDetect) Version

func (md *MobileDetect) Version(propertyName interface{}) string

It is recommended to use VersionKey instead

func (*MobileDetect) VersionFloat

func (md *MobileDetect) VersionFloat(propertyName interface{}) float64

It is recommended to use VersionFloatKey instead

func (*MobileDetect) VersionFloatKey

func (md *MobileDetect) VersionFloatKey(propertyVal int) float64

VersionFloat does the same as Version, but returns a float number good for version comparison

func (*MobileDetect) VersionKey

func (md *MobileDetect) VersionKey(propertyVal int) string

Version detects the browser version returning as string

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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