mirror of
https://github.com/MontFerret/ferret.git
synced 2025-07-05 00:49:00 +02:00
85 lines
1.6 KiB
Go
85 lines
1.6 KiB
Go
package cdp
|
|
|
|
import "github.com/MontFerret/ferret/pkg/drivers"
|
|
|
|
type (
|
|
Options struct {
|
|
*drivers.Options
|
|
Address string
|
|
KeepCookies bool
|
|
}
|
|
|
|
Option func(opts *Options)
|
|
)
|
|
|
|
const DefaultAddress = "http://127.0.0.1:9222"
|
|
|
|
func NewOptions(setters []Option) *Options {
|
|
opts := new(Options)
|
|
opts.Options = new(drivers.Options)
|
|
opts.Name = DriverName
|
|
opts.Address = DefaultAddress
|
|
|
|
for _, setter := range setters {
|
|
setter(opts)
|
|
}
|
|
|
|
return opts
|
|
}
|
|
|
|
func WithAddress(address string) Option {
|
|
return func(opts *Options) {
|
|
if address != "" {
|
|
opts.Address = address
|
|
}
|
|
}
|
|
}
|
|
|
|
func WithProxy(address string) Option {
|
|
return func(opts *Options) {
|
|
drivers.WithProxy(address)(opts.Options)
|
|
}
|
|
}
|
|
|
|
func WithUserAgent(value string) Option {
|
|
return func(opts *Options) {
|
|
drivers.WithUserAgent(value)(opts.Options)
|
|
}
|
|
}
|
|
|
|
func WithKeepCookies() Option {
|
|
return func(opts *Options) {
|
|
opts.KeepCookies = true
|
|
}
|
|
}
|
|
|
|
func WithCustomName(name string) Option {
|
|
return func(opts *Options) {
|
|
drivers.WithCustomName(name)(opts.Options)
|
|
}
|
|
}
|
|
|
|
func WithHeader(name string, header []string) Option {
|
|
return func(opts *Options) {
|
|
drivers.WithHeader(name, header)(opts.Options)
|
|
}
|
|
}
|
|
|
|
func WithHeaders(headers *drivers.HTTPHeaders) Option {
|
|
return func(opts *Options) {
|
|
drivers.WithHeaders(headers)(opts.Options)
|
|
}
|
|
}
|
|
|
|
func WithCookie(cookie drivers.HTTPCookie) Option {
|
|
return func(opts *Options) {
|
|
drivers.WithCookie(cookie)(opts.Options)
|
|
}
|
|
}
|
|
|
|
func WithCookies(cookies []drivers.HTTPCookie) Option {
|
|
return func(opts *Options) {
|
|
drivers.WithCookies(cookies)(opts.Options)
|
|
}
|
|
}
|