-
Notifications
You must be signed in to change notification settings - Fork 0
/
reset.go
64 lines (49 loc) · 1.29 KB
/
reset.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
package gocrawlhq
import (
"fmt"
"net/http"
)
func (c *Client) Reset() (err error) {
expectedStatusCode := 202
req, err := http.NewRequest(http.MethodPost, c.ResetEndpoint.String(), nil)
if err != nil {
return err
}
req.Header.Add("X-Auth-Key", c.Key)
req.Header.Add("X-Auth-Secret", c.Secret)
req.Header.Add("User-Agent", "gocrawlhq/"+Version)
if c.Identifier != "" {
req.Header.Add("X-Identifier", c.Identifier)
}
resp, err := c.HTTPClient.Do(req)
if err != nil {
return err
}
defer resp.Body.Close()
if resp.StatusCode != expectedStatusCode {
return fmt.Errorf("non-%d status code: %d", expectedStatusCode, resp.StatusCode)
}
return nil
}
func (c *Client) ResetURL(ID string) (err error) {
expectedStatusCode := 200
req, err := http.NewRequest(http.MethodPost, c.ResetEndpoint.String()+"/"+ID, nil)
if err != nil {
return err
}
req.Header.Add("X-Auth-Key", c.Key)
req.Header.Add("X-Auth-Secret", c.Secret)
req.Header.Add("User-Agent", "gocrawlhq/"+Version)
if c.Identifier != "" {
req.Header.Add("X-Identifier", c.Identifier)
}
resp, err := c.HTTPClient.Do(req)
if err != nil {
return err
}
defer resp.Body.Close()
if resp.StatusCode != expectedStatusCode {
return fmt.Errorf("non-%d status code: %d", expectedStatusCode, resp.StatusCode)
}
return nil
}