-
Notifications
You must be signed in to change notification settings - Fork 0
/
options.go
92 lines (86 loc) · 2.19 KB
/
options.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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
package hbookerLib
import (
"log"
)
type Options interface {
Apply(client *Client)
}
type OptionFunc func(client *Client)
func (f OptionFunc) Apply(client *Client) {
f(client)
}
func WithLoginToken(loginToken string) Options {
return OptionFunc(func(client *Client) {
if len(loginToken) != 32 {
log.Println("LoginToken is must be 32 length, please check it.")
} else {
client.API.HttpClient.LoginToken = loginToken
}
})
}
func WithAccount(account string) Options {
return OptionFunc(func(client *Client) {
client.API.HttpClient.Account = account
})
}
func WithAccountAndLoginToken(account, loginToken string) Options {
return OptionFunc(func(client *Client) {
WithAccount(account).Apply(client)
WithLoginToken(loginToken).Apply(client)
_, err := client.API.GetUserInfo()
if err != nil {
log.Println(err)
client.API.HttpClient.Account = ""
client.API.HttpClient.LoginToken = ""
return
}
})
}
func WithVersion(version string) Options {
return OptionFunc(func(client *Client) {
client.API.HttpClient.Version = version
})
}
func WithDebug() Options {
return OptionFunc(func(client *Client) {
if client.API.HttpClient.Debug {
client.API.HttpClient.Debug = false
} else {
client.API.HttpClient.Debug = true
}
})
}
func WithOutputDebug() Options {
return OptionFunc(func(client *Client) {
if client.API.HttpClient.OutputDebug {
client.API.HttpClient.OutputDebug = false
} else {
client.API.HttpClient.OutputDebug = true
}
})
}
func WithProxyURLArray(proxyURLArray []string) Options {
return OptionFunc(func(client *Client) {
client.API.HttpClient.ProxyURLArray = proxyURLArray
})
}
func WithProxyURL(proxyURL string) Options {
return OptionFunc(func(client *Client) {
client.API.HttpClient.ProxyURL = proxyURL
})
}
func WithAPIBaseURL(apiBaseURL string) Options {
return OptionFunc(func(client *Client) {
client.API.HttpClient.APIBaseURL = apiBaseURL
})
}
func WithUserAgent(userAgent string) Options {
return OptionFunc(func(client *Client) {
client.API.HttpClient.UserAgent = userAgent
})
}
func WithAndroidApiKey(androidApiKey string) Options {
return OptionFunc(func(client *Client) {
client.API.HttpClient.AndroidApiKey = androidApiKey
})
}