Help us shape the future of Go! Take the 2026 Go Developer Survey

woothee

package module
v1.10.0 Latest Latest
Warning

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

Go to latest
Published: Apr 15, 2019 License: MIT Imports: 3 Imported by: 3

README

woothee-go

Build Status

Coverage Status

Woothee is a multi-language UserAgent detection library, and this is the Go version of Woothee.

import (
    "github.com/woothee/woothee-go"
)

func main() {
    agent := `Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)`
    result, err := woothee.Parse(agent)
    if err != nil {
        log.Fatalf("Could not parse '%s': %s", agent, err)
    }

    /*
        result.Name     = "Googlebot"
        result.Category = "crawler"
        result.Os       = "UNKNOWN"
        result.Type     = "UNKNOWN"
        result.Version  = "UNKNOWN"
        result.Vendor   = "UNKNOWN"
    */
}

Working with the source code

Note: You need to have GOROOT, GOPATH et al set correctly

Fetching the source

go get github.com/woothee/woothee-go

Running Tests

go test -v ./...

Updating woothee definition

If you live on the bleeding edge (i.e. go 1.4 and up):

go generate

Otherwise:

go get gopkg.in/yaml.v2

then

go run maint/gendataset.go

This updates the dataset.go and other tests

Documentation

Overview

This file is auto-generated! Any changes to this file will be lost!

Index

Constants

View Source
const (
	ValueUnknown        = "UNKNOWN"
	CategoryPC          = "pc"
	CategorySmartphone  = "smartphone"
	CategoryMobilephone = "mobilephone"
	CategoryAppliance   = "appliance"
	CategoryCrawler     = "crawler"
	CategoryMisc        = "misc"
)

Variables

View Source
var (
	EmptyResult = &Result{
		Name:      ValueUnknown,
		Category:  ValueUnknown,
		Os:        ValueUnknown,
		OsVersion: ValueUnknown,
		Type:      ValueUnknown,
		Version:   ValueUnknown,
		Vendor:    ValueUnknown,
	}
	ErrNoMatch    = errors.New("no match")
	ErrNoDataSet  = errors.New("no such dataset")
	DefaultParser = NewParser()
)
View Source
var CrawlerPrefixPatterns = []string{
	"Rome Client ",
	"UnwindFetchor/",
	"ia_archiver ",
	"Summify ",
	"PostRank/",
}
View Source
var PHPPrefixPatterns = []string{
	"PHP",
	"WordPress",
	"CakePHP",
	"PukiWiki",
	"PECL::HTTP",
}
View Source
var PearPatterns = []string{
	"PEAR HTTP_Request",
	"HTTP_Request",
}

Functions

This section is empty.

Types

type DataSet

type DataSet map[string]*Result
var DefaultDataSet DataSet = DataSet{
	"MSIE": &Result{
		Name:   "Internet Explorer",
		Type:   "",
		Vendor: "Microsoft",
	},
	"Edge": &Result{
		Name:   "Edge",
		Type:   "",
		Vendor: "Microsoft",
	},
	"Chrome": &Result{
		Name:   "Chrome",
		Type:   "",
		Vendor: "Google",
	},
	"Safari": &Result{
		Name:   "Safari",
		Type:   "",
		Vendor: "Apple",
	},
	"Firefox": &Result{
		Name:   "Firefox",
		Type:   "",
		Vendor: "Mozilla",
	},
	"Opera": &Result{
		Name:   "Opera",
		Type:   "",
		Vendor: "Opera",
	},
	"Vivaldi": &Result{
		Name:   "Vivaldi",
		Type:   "",
		Vendor: "Vivaldi Technologies",
	},
	"Sleipnir": &Result{
		Name:   "Sleipnir",
		Type:   "",
		Vendor: "Fenrir Inc.",
	},
	"Webview": &Result{
		Name:   "Webview",
		Type:   "",
		Vendor: "OS vendor",
	},
	"YaBrowser": &Result{
		Name:   "Yandex Browser",
		Type:   "",
		Vendor: "Yandex",
	},
	"Win": &Result{
		Name:     "Windows UNKNOWN Ver",
		Type:     "pc",
		Category: "pc",
	},
	"Win10": &Result{
		Name:     "Windows 10",
		Type:     "pc",
		Category: "pc",
	},
	"Win8.1": &Result{
		Name:     "Windows 8.1",
		Type:     "pc",
		Category: "pc",
	},
	"Win8": &Result{
		Name:     "Windows 8",
		Type:     "pc",
		Category: "pc",
	},
	"Win7": &Result{
		Name:     "Windows 7",
		Type:     "pc",
		Category: "pc",
	},
	"WinVista": &Result{
		Name:     "Windows Vista",
		Type:     "pc",
		Category: "pc",
	},
	"WinXP": &Result{
		Name:     "Windows XP",
		Type:     "pc",
		Category: "pc",
	},
	"Win2000": &Result{
		Name:     "Windows 2000",
		Type:     "pc",
		Category: "pc",
	},
	"WinNT4": &Result{
		Name:     "Windows NT 4.0",
		Type:     "pc",
		Category: "pc",
	},
	"WinMe": &Result{
		Name:     "Windows Me",
		Type:     "pc",
		Category: "pc",
	},
	"Win98": &Result{
		Name:     "Windows 98",
		Type:     "pc",
		Category: "pc",
	},
	"Win95": &Result{
		Name:     "Windows 95",
		Type:     "pc",
		Category: "pc",
	},
	"WinPhone": &Result{
		Name:     "Windows Phone OS",
		Type:     "smartphone",
		Category: "smartphone",
	},
	"WinCE": &Result{
		Name:     "Windows CE",
		Type:     "smartphone",
		Category: "smartphone",
	},
	"OSX": &Result{
		Name:     "Mac OSX",
		Type:     "pc",
		Category: "pc",
	},
	"MacOS": &Result{
		Name:     "Mac OS Classic",
		Type:     "pc",
		Category: "pc",
	},
	"Linux": &Result{
		Name:     "Linux",
		Type:     "pc",
		Category: "pc",
	},
	"BSD": &Result{
		Name:     "BSD",
		Type:     "pc",
		Category: "pc",
	},
	"ChromeOS": &Result{
		Name:     "ChromeOS",
		Type:     "pc",
		Category: "pc",
	},
	"Android": &Result{
		Name:     "Android",
		Type:     "smartphone",
		Category: "smartphone",
	},
	"iPhone": &Result{
		Name:     "iPhone",
		Type:     "smartphone",
		Category: "smartphone",
	},
	"iPad": &Result{
		Name:     "iPad",
		Type:     "smartphone",
		Category: "smartphone",
	},
	"iPod": &Result{
		Name:     "iPod",
		Type:     "smartphone",
		Category: "smartphone",
	},
	"iOS": &Result{
		Name:     "iOS",
		Type:     "smartphone",
		Category: "smartphone",
	},
	"FirefoxOS": &Result{
		Name:     "Firefox OS",
		Type:     "smartphone",
		Category: "smartphone",
	},
	"BlackBerry": &Result{
		Name:     "BlackBerry",
		Type:     "smartphone",
		Category: "smartphone",
	},
	"BlackBerry10": &Result{
		Name:     "BlackBerry 10",
		Type:     "smartphone",
		Category: "smartphone",
	},
	"docomo": &Result{
		Name:     "docomo",
		Type:     "mobilephone",
		Vendor:   "docomo",
		Category: "mobilephone",
		Os:       "docomo",
	},
	"au": &Result{
		Name:     "au by KDDI",
		Type:     "mobilephone",
		Vendor:   "au",
		Category: "mobilephone",
		Os:       "au",
	},
	"SoftBank": &Result{
		Name:     "SoftBank Mobile",
		Type:     "mobilephone",
		Vendor:   "SoftBank",
		Category: "mobilephone",
		Os:       "SoftBank",
	},
	"willcom": &Result{
		Name:     "WILLCOM",
		Type:     "mobilephone",
		Vendor:   "WILLCOM",
		Category: "mobilephone",
		Os:       "WILLCOM",
	},
	"jig": &Result{
		Name:     "jig browser",
		Type:     "mobilephone",
		Vendor:   "",
		Category: "mobilephone",
		Os:       "jig",
	},
	"emobile": &Result{
		Name:     "emobile",
		Type:     "mobilephone",
		Vendor:   "",
		Category: "mobilephone",
		Os:       "emobile",
	},
	"SymbianOS": &Result{
		Name:     "SymbianOS",
		Type:     "mobilephone",
		Vendor:   "",
		Category: "mobilephone",
		Os:       "SymbianOS",
	},
	"MobileTranscoder": &Result{
		Name:     "Mobile Transcoder",
		Type:     "mobilephone",
		Vendor:   "",
		Category: "mobilephone",
		Os:       "Mobile Transcoder",
	},
	"Nintendo3DS": &Result{
		Name:     "Nintendo 3DS",
		Type:     "appliance",
		Vendor:   "Nintendo",
		Category: "appliance",
		Os:       "Nintendo 3DS",
	},
	"NintendoDSi": &Result{
		Name:     "Nintendo DSi",
		Type:     "appliance",
		Vendor:   "Nintendo",
		Category: "appliance",
		Os:       "Nintendo DSi",
	},
	"NintendoWii": &Result{
		Name:     "Nintendo Wii",
		Type:     "appliance",
		Vendor:   "Nintendo",
		Category: "appliance",
		Os:       "Nintendo Wii",
	},
	"NintendoWiiU": &Result{
		Name:     "Nintendo Wii U",
		Type:     "appliance",
		Vendor:   "Nintendo",
		Category: "appliance",
		Os:       "Nintendo Wii U",
	},
	"PSP": &Result{
		Name:     "PlayStation Portable",
		Type:     "appliance",
		Vendor:   "Sony",
		Category: "appliance",
		Os:       "PlayStation Portable",
	},
	"PSVita": &Result{
		Name:     "PlayStation Vita",
		Type:     "appliance",
		Vendor:   "Sony",
		Category: "appliance",
		Os:       "PlayStation Vita",
	},
	"PS3": &Result{
		Name:     "PlayStation 3",
		Type:     "appliance",
		Vendor:   "Sony",
		Category: "appliance",
		Os:       "PlayStation 3",
	},
	"PS4": &Result{
		Name:     "PlayStation 4",
		Type:     "appliance",
		Vendor:   "Sony",
		Category: "appliance",
		Os:       "PlayStation 4",
	},
	"Xbox360": &Result{
		Name:     "Xbox 360",
		Type:     "appliance",
		Vendor:   "Microsoft",
		Category: "appliance",
		Os:       "Xbox 360",
	},
	"XboxOne": &Result{
		Name:     "Xbox One",
		Type:     "appliance",
		Vendor:   "Microsoft",
		Category: "appliance",
		Os:       "Xbox One",
	},
	"DigitalTV": &Result{
		Name:     "InternetTVBrowser",
		Type:     "appliance",
		Vendor:   "",
		Category: "appliance",
		Os:       "DigitalTV",
	},
	"SafariRSSReader": &Result{
		Name:     "Safari RSSReader",
		Type:     "misc",
		Vendor:   "Apple",
		Category: "misc",
		Os:       "UNKNOWN",
	},
	"GoogleDesktop": &Result{
		Name:     "Google Desktop",
		Type:     "misc",
		Vendor:   "Google",
		Category: "misc",
		Os:       "UNKNOWN",
	},
	"WindowsRSSReader": &Result{
		Name:     "Windows RSSReader",
		Type:     "misc",
		Vendor:   "Microsoft",
		Category: "misc",
		Os:       "UNKNOWN",
	},
	"VariousRSSReader": &Result{
		Name:     "RSSReader",
		Type:     "misc",
		Vendor:   "",
		Category: "misc",
		Os:       "UNKNOWN",
	},
	"HTTPLibrary": &Result{
		Name:     "HTTP Library",
		Type:     "misc",
		Vendor:   "",
		Category: "misc",
		Os:       "UNKNOWN",
	},
	"GoogleBot": &Result{
		Name:     "Googlebot",
		Type:     "crawler",
		Vendor:   "",
		Category: "crawler",
		Os:       "UNKNOWN",
	},
	"GoogleBotMobile": &Result{
		Name:     "Googlebot Mobile",
		Type:     "crawler",
		Vendor:   "",
		Category: "crawler",
		Os:       "UNKNOWN",
	},
	"GoogleMediaPartners": &Result{
		Name:     "Google Mediapartners",
		Type:     "crawler",
		Vendor:   "",
		Category: "crawler",
		Os:       "UNKNOWN",
	},
	"GoogleFeedFetcher": &Result{
		Name:     "Google Feedfetcher",
		Type:     "crawler",
		Vendor:   "",
		Category: "crawler",
		Os:       "UNKNOWN",
	},
	"GoogleAppEngine": &Result{
		Name:     "Google AppEngine",
		Type:     "crawler",
		Vendor:   "",
		Category: "crawler",
		Os:       "UNKNOWN",
	},
	"GoogleWebPreview": &Result{
		Name:     "Google Web Preview",
		Type:     "crawler",
		Vendor:   "",
		Category: "crawler",
		Os:       "UNKNOWN",
	},
	"YahooSlurp": &Result{
		Name:     "Yahoo! Slurp",
		Type:     "crawler",
		Vendor:   "",
		Category: "crawler",
		Os:       "UNKNOWN",
	},
	"YahooJP": &Result{
		Name:     "Yahoo! Japan",
		Type:     "crawler",
		Vendor:   "",
		Category: "crawler",
		Os:       "UNKNOWN",
	},
	"YahooPipes": &Result{
		Name:     "Yahoo! Pipes",
		Type:     "crawler",
		Vendor:   "",
		Category: "crawler",
		Os:       "UNKNOWN",
	},
	"Baiduspider": &Result{
		Name:     "Baiduspider",
		Type:     "crawler",
		Vendor:   "",
		Category: "crawler",
		Os:       "UNKNOWN",
	},
	"msnbot": &Result{
		Name:     "msnbot",
		Type:     "crawler",
		Vendor:   "",
		Category: "crawler",
		Os:       "UNKNOWN",
	},
	"bingbot": &Result{
		Name:     "bingbot",
		Type:     "crawler",
		Vendor:   "",
		Category: "crawler",
		Os:       "UNKNOWN",
	},
	"BingPreview": &Result{
		Name:     "BingPreview",
		Type:     "crawler",
		Vendor:   "",
		Category: "crawler",
		Os:       "UNKNOWN",
	},
	"Yeti": &Result{
		Name:     "Naver Yeti",
		Type:     "crawler",
		Vendor:   "",
		Category: "crawler",
		Os:       "UNKNOWN",
	},
	"FeedBurner": &Result{
		Name:     "Google FeedBurner",
		Type:     "crawler",
		Vendor:   "",
		Category: "crawler",
		Os:       "UNKNOWN",
	},
	"facebook": &Result{
		Name:     "facebook",
		Type:     "crawler",
		Vendor:   "",
		Category: "crawler",
		Os:       "UNKNOWN",
	},
	"twitter": &Result{
		Name:     "twitter",
		Type:     "crawler",
		Vendor:   "",
		Category: "crawler",
		Os:       "UNKNOWN",
	},
	"trendictionbot": &Result{
		Name:     "trendiction",
		Type:     "crawler",
		Vendor:   "",
		Category: "crawler",
		Os:       "UNKNOWN",
	},
	"mixi": &Result{
		Name:     "mixi",
		Type:     "crawler",
		Vendor:   "",
		Category: "crawler",
		Os:       "UNKNOWN",
	},
	"IndyLibrary": &Result{
		Name:     "Indy Library",
		Type:     "crawler",
		Vendor:   "",
		Category: "crawler",
		Os:       "UNKNOWN",
	},
	"ApplePubSub": &Result{
		Name:     "Apple iCloud",
		Type:     "crawler",
		Vendor:   "",
		Category: "crawler",
		Os:       "UNKNOWN",
	},
	"Genieo": &Result{
		Name:     "Genieo Web Filter",
		Type:     "crawler",
		Vendor:   "",
		Category: "crawler",
		Os:       "UNKNOWN",
	},
	"topsyButterfly": &Result{
		Name:     "topsy Butterfly",
		Type:     "crawler",
		Vendor:   "",
		Category: "crawler",
		Os:       "UNKNOWN",
	},
	"rogerbot": &Result{
		Name:     "SeoMoz rogerbot",
		Type:     "crawler",
		Vendor:   "",
		Category: "crawler",
		Os:       "UNKNOWN",
	},
	"AhrefsBot": &Result{
		Name:     "ahref AhrefsBot",
		Type:     "crawler",
		Vendor:   "",
		Category: "crawler",
		Os:       "UNKNOWN",
	},
	"radian6": &Result{
		Name:     "salesforce radian6",
		Type:     "crawler",
		Vendor:   "",
		Category: "crawler",
		Os:       "UNKNOWN",
	},
	"Hatena": &Result{
		Name:     "Hatena",
		Type:     "crawler",
		Vendor:   "",
		Category: "crawler",
		Os:       "UNKNOWN",
	},
	"goo": &Result{
		Name:     "goo",
		Type:     "crawler",
		Vendor:   "",
		Category: "crawler",
		Os:       "UNKNOWN",
	},
	"livedoorFeedFetcher": &Result{
		Name:     "livedoor FeedFetcher",
		Type:     "crawler",
		Vendor:   "",
		Category: "crawler",
		Os:       "UNKNOWN",
	},
	"VariousCrawler": &Result{
		Name:     "misc crawler",
		Type:     "crawler",
		Vendor:   "",
		Category: "crawler",
		Os:       "UNKNOWN",
	},
}

type Parser

type Parser struct {
	AgentDataSet DataSet
}

func NewParser

func NewParser() *Parser

func (*Parser) ChallengeAppliance

func (p *Parser) ChallengeAppliance(agent string, result *Result) error

func (*Parser) ChallengeAu

func (p *Parser) ChallengeAu(agent string, result *Result) error

func (*Parser) ChallengeCrawlers

func (p *Parser) ChallengeCrawlers(agent string, result *Result) error

func (*Parser) ChallengeDesktopTools

func (p *Parser) ChallengeDesktopTools(agent string, result *Result) error

func (*Parser) ChallengeDigitalTv

func (p *Parser) ChallengeDigitalTv(agent string, result *Result) error

func (*Parser) ChallengeDocomo

func (p *Parser) ChallengeDocomo(agent string, result *Result) error

func (*Parser) ChallengeFirefox

func (p *Parser) ChallengeFirefox(agent string, result *Result) error

func (*Parser) ChallengeFirefoxiOS added in v1.8.0

func (p *Parser) ChallengeFirefoxiOS(agent string, result *Result) error

func (*Parser) ChallengeGoogle

func (p *Parser) ChallengeGoogle(agent string, result *Result) error

func (*Parser) ChallengeHTTPLibrary

func (p *Parser) ChallengeHTTPLibrary(agent string, result *Result) error

func (*Parser) ChallengeLinux

func (p *Parser) ChallengeLinux(agent string, result *Result) error

func (*Parser) ChallengeMaybeCrawler

func (p *Parser) ChallengeMaybeCrawler(agent string, result *Result) error

func (*Parser) ChallengeMaybeRssReader

func (p *Parser) ChallengeMaybeRssReader(agent string, result *Result) error

func (*Parser) ChallengeMiscMobilephone

func (p *Parser) ChallengeMiscMobilephone(agent string, result *Result) error

func (*Parser) ChallengeMiscOs

func (p *Parser) ChallengeMiscOs(agent string, result *Result) error

func (*Parser) ChallengeMobilephone

func (p *Parser) ChallengeMobilephone(agent string, result *Result) error

func (*Parser) ChallengeMsEdge added in v1.8.0

func (p *Parser) ChallengeMsEdge(agent string, result *Result) error

func (*Parser) ChallengeMsie

func (p *Parser) ChallengeMsie(agent string, result *Result) error

func (*Parser) ChallengeNintendo

func (p *Parser) ChallengeNintendo(agent string, result *Result) error

func (*Parser) ChallengeOpera

func (p *Parser) ChallengeOpera(agent string, result *Result) error

func (*Parser) ChallengeOsx

func (p *Parser) ChallengeOsx(agent string, result *Result) error

func (*Parser) ChallengePlaystation

func (p *Parser) ChallengePlaystation(agent string, result *Result) error

func (*Parser) ChallengeSafariChrome

func (p *Parser) ChallengeSafariChrome(agent string, result *Result) error

func (*Parser) ChallengeSleipnir

func (p *Parser) ChallengeSleipnir(agent string, result *Result) error

func (*Parser) ChallengeSmartphone

func (p *Parser) ChallengeSmartphone(agent string, result *Result) error

func (*Parser) ChallengeSmartphonePatterns

func (p *Parser) ChallengeSmartphonePatterns(agent string, result *Result) error

func (*Parser) ChallengeSoftbank

func (p *Parser) ChallengeSoftbank(agent string, result *Result) error

func (*Parser) ChallengeVivaldi added in v1.8.0

func (p *Parser) ChallengeVivaldi(agent string, result *Result) error

func (*Parser) ChallengeWebview added in v1.8.0

func (p *Parser) ChallengeWebview(agent string, result *Result) error

func (*Parser) ChallengeWillcom

func (p *Parser) ChallengeWillcom(agent string, result *Result) error

func (*Parser) ChallengeWindows

func (p *Parser) ChallengeWindows(agent string, result *Result) error

func (*Parser) ChallengeYandexBrowser added in v1.8.0

func (p *Parser) ChallengeYandexBrowser(agent string, result *Result) error

func (*Parser) LookupDataSet

func (p *Parser) LookupDataSet(label string) (*Result, error)

func (*Parser) Parse

func (p *Parser) Parse(agent string) (result *Result, err error)

func (*Parser) PopulateDataSet

func (p *Parser) PopulateDataSet(result *Result, label string) error

func (*Parser) TryAppliance

func (p *Parser) TryAppliance(agent string, result *Result) (err error)

func (*Parser) TryBrowser

func (p *Parser) TryBrowser(agent string, result *Result) (err error)

func (*Parser) TryCrawler

func (p *Parser) TryCrawler(agent string, result *Result) (err error)

func (*Parser) TryMisc

func (p *Parser) TryMisc(agent string, result *Result) (err error)

func (*Parser) TryMobilephone

func (p *Parser) TryMobilephone(agent string, result *Result) (err error)

func (*Parser) TryOs

func (p *Parser) TryOs(agent string, result *Result) (err error)

func (*Parser) TryRareCases

func (p *Parser) TryRareCases(agent string, result *Result) (err error)

type Result

type Result struct {
	Name      string `json:"name"`
	Category  string `json:"category"`
	Os        string `json:"os"`
	OsVersion string `json:"os_version"`
	Type      string `json:"type"`
	Version   string `json:"version"`
	Vendor    string `json:"vendor"`
}

func Parse

func Parse(agent string) (*Result, error)

Parse parses the given agent string, and returns a Result struct or an error if any

func (*Result) Clone

func (r *Result) Clone() *Result

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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