-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathclient.go
67 lines (54 loc) · 1.21 KB
/
client.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
55
56
57
58
59
60
61
62
63
64
65
66
67
package devicedetector
import (
"strings"
"github.com/robicode/device-detector/util"
"github.com/robicode/device-detector/versionextractor"
)
type Client struct {
_cache *Cache
_client *CachedClient
_userAgent string
}
var clientFilenames = []string{
"client/feed_readers.yml",
"client/mobile_apps.yml",
"client/mediaplayers.yml",
"client/pim.yml",
"client/browsers.yml",
"client/libraries.yml",
}
func NewClient(cache *Cache, userAgent string) *Client {
c := Client{
_cache: cache,
_userAgent: userAgent,
}
c._client = cache.Client.Find(userAgent)
return &c
}
func (c *Client) Name() string {
if c._client != nil {
return c._client.Name
}
return ""
}
func (c *Client) Engine() string {
if c._client != nil {
return c._client.Engine.Default
}
return ""
}
func (c *Client) FullVersion() string {
if c._client != nil {
return versionextractor.New(c._userAgent, util.FixupRegex(c._client.Regex), c._client.Version, nil).Call()
}
return ""
}
func (c *Client) isMobileOnlyBrowser() bool {
return mobileOnlyBrowser(c.Name())
}
func (c *Client) IsKnown() bool {
return c._client != nil
}
func (c *Client) IsBrowser() bool {
return strings.Contains(c._client.Path, "client/browsers.yml")
}