2018-12-21 23:14:41 -05:00
|
|
|
package cdp
|
2018-10-07 21:23:36 -04:00
|
|
|
|
2019-09-05 11:49:21 -04:00
|
|
|
import "github.com/MontFerret/ferret/pkg/drivers"
|
|
|
|
|
2018-10-07 21:23:36 -04:00
|
|
|
type (
|
|
|
|
Options struct {
|
2021-03-26 12:01:00 -04:00
|
|
|
*drivers.Options
|
2019-03-15 19:59:05 -04:00
|
|
|
Address string
|
|
|
|
KeepCookies bool
|
2018-10-07 21:23:36 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
Option func(opts *Options)
|
|
|
|
)
|
|
|
|
|
2018-12-21 23:14:41 -05:00
|
|
|
const DefaultAddress = "http://127.0.0.1:9222"
|
|
|
|
|
2021-03-26 12:01:00 -04:00
|
|
|
func NewOptions(setters []Option) *Options {
|
2018-11-30 19:30:55 -05:00
|
|
|
opts := new(Options)
|
2021-03-26 12:01:00 -04:00
|
|
|
opts.Options = new(drivers.Options)
|
2019-03-15 19:59:05 -04:00
|
|
|
opts.Name = DriverName
|
|
|
|
opts.Address = DefaultAddress
|
2018-11-30 19:30:55 -05:00
|
|
|
|
|
|
|
for _, setter := range setters {
|
|
|
|
setter(opts)
|
|
|
|
}
|
|
|
|
|
|
|
|
return opts
|
|
|
|
}
|
|
|
|
|
2018-12-21 23:14:41 -05:00
|
|
|
func WithAddress(address string) Option {
|
2018-11-30 19:30:55 -05:00
|
|
|
return func(opts *Options) {
|
2019-03-06 22:54:12 -05:00
|
|
|
if address != "" {
|
2019-03-15 19:59:05 -04:00
|
|
|
opts.Address = address
|
2019-03-06 22:54:12 -05:00
|
|
|
}
|
2018-11-30 19:30:55 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-10-07 21:23:36 -04:00
|
|
|
func WithProxy(address string) Option {
|
|
|
|
return func(opts *Options) {
|
2021-03-26 12:01:00 -04:00
|
|
|
drivers.WithProxy(address)(opts.Options)
|
2018-10-07 21:23:36 -04:00
|
|
|
}
|
|
|
|
}
|
2018-10-07 22:18:57 -04:00
|
|
|
|
|
|
|
func WithUserAgent(value string) Option {
|
|
|
|
return func(opts *Options) {
|
2021-03-26 12:01:00 -04:00
|
|
|
drivers.WithUserAgent(value)(opts.Options)
|
2019-03-15 19:59:05 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func WithKeepCookies() Option {
|
|
|
|
return func(opts *Options) {
|
|
|
|
opts.KeepCookies = true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func WithCustomName(name string) Option {
|
|
|
|
return func(opts *Options) {
|
2021-03-26 12:01:00 -04:00
|
|
|
drivers.WithCustomName(name)(opts.Options)
|
2018-10-07 22:18:57 -04:00
|
|
|
}
|
|
|
|
}
|
2019-09-05 11:49:21 -04:00
|
|
|
|
2021-03-26 12:01:00 -04:00
|
|
|
func WithHeader(name string, header []string) Option {
|
2019-09-05 11:49:21 -04:00
|
|
|
return func(opts *Options) {
|
2021-03-26 12:01:00 -04:00
|
|
|
drivers.WithHeader(name, header)(opts.Options)
|
2019-09-05 11:49:21 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-03-26 12:01:00 -04:00
|
|
|
func WithHeaders(headers *drivers.HTTPHeaders) Option {
|
2019-09-05 11:49:21 -04:00
|
|
|
return func(opts *Options) {
|
2021-03-26 12:01:00 -04:00
|
|
|
drivers.WithHeaders(headers)(opts.Options)
|
2019-09-05 11:49:21 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func WithCookie(cookie drivers.HTTPCookie) Option {
|
|
|
|
return func(opts *Options) {
|
2021-03-26 12:01:00 -04:00
|
|
|
drivers.WithCookie(cookie)(opts.Options)
|
2019-09-05 11:49:21 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func WithCookies(cookies []drivers.HTTPCookie) Option {
|
|
|
|
return func(opts *Options) {
|
2021-03-26 12:01:00 -04:00
|
|
|
drivers.WithCookies(cookies)(opts.Options)
|
2019-09-05 11:49:21 -04:00
|
|
|
}
|
|
|
|
}
|