-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgocrawlhq.go
71 lines (58 loc) · 1.4 KB
/
gocrawlhq.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
68
69
70
71
package gocrawlhq
import (
"net/http"
"net/url"
"os"
"path"
"time"
)
var (
Version = "1.2.15"
)
func Init(key, secret, project, address, identifier string) (c *Client, err error) {
c = new(Client)
c.Key = key
c.Secret = secret
c.Project = project
c.HQAddress = address
c.HTTPClient = &http.Client{
Timeout: time.Second * 5,
}
if identifier == "" {
// Initialize the identifier
hostname, err := os.Hostname()
if err != nil {
return c, err
}
c.Identifier = hostname + "-" + project
} else {
c.Identifier = identifier
}
// Initialize the websocket connection
err = c.InitWebsocketConn()
if err != nil {
return c, err
}
// Initialize the endpoints
c.URLsEndpoint, err = url.Parse(c.HQAddress)
if err != nil {
return c, err
}
c.SeencheckEndpoint, err = url.Parse(c.HQAddress)
if err != nil {
return c, err
}
c.ResetEndpoint, err = url.Parse(c.HQAddress)
if err != nil {
return c, err
}
c.ProjectEndpoint, err = url.Parse(c.HQAddress)
if err != nil {
return c, err
}
c.URLsEndpoint.Path = path.Join(c.URLsEndpoint.Path, "api", "projects", c.Project, "urls")
c.SeencheckEndpoint.Path = path.Join(c.SeencheckEndpoint.Path, "api", "projects", c.Project, "seencheck")
c.ResetEndpoint.Path = path.Join(c.ResetEndpoint.Path, "api", "projects", c.Project, "reset")
c.ProjectEndpoint.Path = path.Join(c.ProjectEndpoint.Path, "api", "projects", c.Project)
return c, nil
}