-
Notifications
You must be signed in to change notification settings - Fork 0
/
client.go
53 lines (46 loc) · 998 Bytes
/
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
package main
import (
"net/http"
"net/http/cookiejar"
"net/url"
"time"
)
type IGoerClient interface {
Do(req *http.Request) (*http.Response, error)
DeleteSessionId(domain string) error
}
type GoerClient struct {
HttpClient *http.Client
}
func NewGoerClient() *GoerClient {
if jar, err := cookiejar.New(nil); err != nil {
panic(SystemFailureMessage + err.Error())
} else {
return &GoerClient{
&http.Client{
Jar: jar,
Timeout: 60 * time.Second,
CheckRedirect: func(req *http.Request, via []*http.Request) error {
return http.ErrUseLastResponse
},
},
}
}
}
func (c *GoerClient) Do(req *http.Request) (*http.Response, error) {
return c.HttpClient.Do(req)
}
func (c *GoerClient) DeleteSessionId(domain string) error {
if url, err := url.Parse(domain); err != nil {
return err
} else {
c.HttpClient.Jar.SetCookies(url, []*http.Cookie{
{
Name: SessionIDCookieField,
Value: "",
HttpOnly: true,
},
})
return nil
}
}