-
Notifications
You must be signed in to change notification settings - Fork 43
/
config.go
60 lines (50 loc) · 1.63 KB
/
config.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
package simple
type BrowserConfig struct {
wsAddress string
proxyAddress string
proxyUsername string
proxyPassword string
noSandBox bool
headless bool
responseModification []*ResponseModification
requestModification []*RequestModification
}
type BrowserConfigOpt func(*BrowserConfig)
func WithWsAddress(wsAddress string) BrowserConfigOpt {
return func(config *BrowserConfig) {
config.wsAddress = wsAddress
}
}
func WithProxy(proxyAddress string, proxyUserInfo ...string) BrowserConfigOpt {
return func(config *BrowserConfig) {
config.proxyAddress = proxyAddress
if len(proxyUserInfo) > 1 {
config.proxyUsername = proxyUserInfo[0]
config.proxyPassword = proxyUserInfo[1]
}
}
}
func WithNoSandBox(noSandBox bool) BrowserConfigOpt {
return func(config *BrowserConfig) {
config.noSandBox = noSandBox
}
}
func WithHeadless(headless bool) BrowserConfigOpt {
return func(config *BrowserConfig) {
config.headless = headless
}
}
func WithResponseModification(modifyUrl string, modifyTarget ModifyTarget, modifyResult interface{}) BrowserConfigOpt {
return func(config *BrowserConfig) {
config.responseModification = append(config.responseModification, &ResponseModification{
baseModify{modifyUrl: modifyUrl, modifyTarget: modifyTarget, modifyResult: modifyResult},
})
}
}
func WithRequestModification(modifyUrl string, modifyTarget ModifyTarget, modifyResult interface{}) BrowserConfigOpt {
return func(config *BrowserConfig) {
config.requestModification = append(config.requestModification, &RequestModification{
baseModify{modifyUrl: modifyUrl, modifyTarget: modifyTarget, modifyResult: modifyResult},
})
}
}