-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
helpers.go
54 lines (43 loc) · 1.3 KB
/
helpers.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
package useragent
import (
"strings"
)
// IsDesktop returns true if the user agent is a desktop browser.
func (ua UserAgent) IsDesktop() bool {
return ua.desktop
}
// IsMobile returns true if the user agent is a mobile browser.
func (ua UserAgent) IsMobile() bool {
return ua.mobile
}
// IsTablet returns true if the user agent is a tablet browser.
func (ua UserAgent) IsTablet() bool {
return ua.tablet
}
// IsTV returns true if the user agent is a TV browser.
func (ua UserAgent) IsTV() bool {
return ua.tv
}
// IsBot returns true if the user agent is a bot.
func (ua UserAgent) IsBot() bool {
return ua.bot
}
// GetBrowser returns the browser name. If no browser is found, it returns an empty string.
func (ua UserAgent) GetBrowser() string {
return ua.browser
}
// GetOS returns the operating system name. If no OS is found, it returns an empty string.
func (ua UserAgent) GetOS() string {
return ua.os
}
// GetVersion returns the browser version. If no version is found, it returns an empty string.
func (ua UserAgent) GetVersion() string {
return ua.version
}
// GetMajorVersion returns the major version of the browser. If no version is found, it returns an empty string.
func (ua UserAgent) GetMajorVersion() string {
if ua.version == "" {
return ""
}
return strings.Split(ua.version, ".")[0]
}