-
Notifications
You must be signed in to change notification settings - Fork 0
/
base.go
74 lines (61 loc) · 1.15 KB
/
base.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
72
73
74
package qweather
import (
"net/http"
"time"
)
type Config struct {
Timeout time.Duration
Proxy *http.Transport
CheckRedirect func(req *http.Request, via []*http.Request) error
Jar http.CookieJar
}
func (c *Config) BuildClient() Client {
return &DefaultClient{
Client: &http.Client{
Timeout: c.Timeout,
Transport: c.Proxy,
CheckRedirect: c.CheckRedirect,
Jar: c.Jar,
},
}
}
type doClient interface {
Do(r *http.Request) (*http.Response, error)
}
type Client interface {
doClient
}
type DefaultClient struct {
*http.Client
}
func NewDefaultClient() *DefaultClient {
return &DefaultClient{
Client: http.DefaultClient,
}
}
func (c *DefaultClient) SetConfig(config *Config) {
c.Timeout = config.Timeout
c.Transport = config.Proxy
c.CheckRedirect = config.CheckRedirect
c.Jar = config.Jar
}
type Credential struct {
Key string
PublicID string
Encrypt bool
}
func (c *Credential) SetEncrypt() *Credential {
c.Encrypt = true
return c
}
func (c *Credential) UnsetEncrypt() *Credential {
c.Encrypt = false
return c
}
type Version uint8
const (
_ Version = iota
Free
Standard
Pro
)