2018-12-22 06:14:41 +02:00
|
|
|
package cdp
|
2018-10-08 03:23:36 +02:00
|
|
|
|
|
|
|
type (
|
|
|
|
Options struct {
|
2019-03-16 01:59:05 +02:00
|
|
|
Name string
|
|
|
|
Proxy string
|
|
|
|
UserAgent string
|
|
|
|
Address string
|
|
|
|
KeepCookies bool
|
2018-10-08 03:23:36 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
Option func(opts *Options)
|
|
|
|
)
|
|
|
|
|
2018-12-22 06:14:41 +02:00
|
|
|
const DefaultAddress = "http://127.0.0.1:9222"
|
|
|
|
|
2018-12-01 02:30:55 +02:00
|
|
|
func newOptions(setters []Option) *Options {
|
|
|
|
opts := new(Options)
|
2019-03-16 01:59:05 +02:00
|
|
|
opts.Name = DriverName
|
|
|
|
opts.Address = DefaultAddress
|
2018-12-01 02:30:55 +02:00
|
|
|
|
|
|
|
for _, setter := range setters {
|
|
|
|
setter(opts)
|
|
|
|
}
|
|
|
|
|
|
|
|
return opts
|
|
|
|
}
|
|
|
|
|
2018-12-22 06:14:41 +02:00
|
|
|
func WithAddress(address string) Option {
|
2018-12-01 02:30:55 +02:00
|
|
|
return func(opts *Options) {
|
2019-03-07 05:54:12 +02:00
|
|
|
if address != "" {
|
2019-03-16 01:59:05 +02:00
|
|
|
opts.Address = address
|
2019-03-07 05:54:12 +02:00
|
|
|
}
|
2018-12-01 02:30:55 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-10-08 03:23:36 +02:00
|
|
|
func WithProxy(address string) Option {
|
|
|
|
return func(opts *Options) {
|
2019-03-16 01:59:05 +02:00
|
|
|
opts.Proxy = address
|
2018-10-08 03:23:36 +02:00
|
|
|
}
|
|
|
|
}
|
2018-10-08 04:18:57 +02:00
|
|
|
|
|
|
|
func WithUserAgent(value string) Option {
|
|
|
|
return func(opts *Options) {
|
2019-03-16 01:59:05 +02:00
|
|
|
opts.UserAgent = value
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func WithKeepCookies() Option {
|
|
|
|
return func(opts *Options) {
|
|
|
|
opts.KeepCookies = true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func WithCustomName(name string) Option {
|
|
|
|
return func(opts *Options) {
|
|
|
|
opts.Name = name
|
2018-10-08 04:18:57 +02:00
|
|
|
}
|
|
|
|
}
|