-
Notifications
You must be signed in to change notification settings - Fork 6
/
woothee.go
54 lines (47 loc) · 1.26 KB
/
woothee.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
//go:generate go get gopkg.in/yaml.v2
//go:generate go run maint/gendataset.go
package woothee
import (
"errors"
)
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"`
}
type DataSet map[string]*Result
const (
ValueUnknown = "UNKNOWN"
CategoryPC = "pc"
CategorySmartphone = "smartphone"
CategoryMobilephone = "mobilephone"
CategoryAppliance = "appliance"
CategoryCrawler = "crawler"
CategoryMisc = "misc"
)
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()
)
func (r *Result) Clone() *Result {
return &Result{r.Name, r.Category, r.Os, r.OsVersion, r.Type, r.Version, r.Vendor}
}
// Parse parses the given agent string, and returns a Result struct or
// an error if any
func Parse(agent string) (*Result, error) {
return DefaultParser.Parse(agent)
}