2018-09-26 03:49:42 +02:00
|
|
|
package cli
|
2018-09-23 08:05:05 +02:00
|
|
|
|
2018-12-01 02:30:55 +02:00
|
|
|
import (
|
|
|
|
"context"
|
2019-02-20 01:10:18 +02:00
|
|
|
|
2018-12-22 06:14:41 +02:00
|
|
|
"github.com/MontFerret/ferret/pkg/drivers"
|
|
|
|
"github.com/MontFerret/ferret/pkg/drivers/cdp"
|
|
|
|
"github.com/MontFerret/ferret/pkg/drivers/http"
|
2018-12-01 02:30:55 +02:00
|
|
|
)
|
|
|
|
|
2018-09-23 08:05:05 +02:00
|
|
|
type Options struct {
|
2018-10-08 04:18:57 +02:00
|
|
|
Cdp string
|
|
|
|
Params map[string]interface{}
|
|
|
|
Proxy string
|
|
|
|
UserAgent string
|
2018-10-11 18:39:03 +02:00
|
|
|
ShowTime bool
|
2018-09-23 08:05:05 +02:00
|
|
|
}
|
2018-12-01 02:30:55 +02:00
|
|
|
|
2019-02-26 22:32:50 +02:00
|
|
|
func (opts Options) WithContext(ctx context.Context) (context.Context, context.CancelFunc) {
|
|
|
|
httpDriver := http.NewDriver(
|
|
|
|
http.WithProxy(opts.Proxy),
|
|
|
|
http.WithUserAgent(opts.UserAgent),
|
|
|
|
)
|
|
|
|
|
2019-02-20 01:10:18 +02:00
|
|
|
ctx = drivers.WithContext(
|
|
|
|
ctx,
|
2019-02-26 22:32:50 +02:00
|
|
|
httpDriver,
|
2019-02-20 01:10:18 +02:00
|
|
|
drivers.AsDefault(),
|
|
|
|
)
|
2018-12-22 06:14:41 +02:00
|
|
|
|
2019-02-26 22:32:50 +02:00
|
|
|
cdpDriver := cdp.NewDriver(
|
|
|
|
cdp.WithAddress(opts.Cdp),
|
|
|
|
cdp.WithProxy(opts.Proxy),
|
|
|
|
cdp.WithUserAgent(opts.UserAgent),
|
|
|
|
)
|
|
|
|
|
2019-02-20 01:10:18 +02:00
|
|
|
ctx = drivers.WithContext(
|
2018-12-01 02:30:55 +02:00
|
|
|
ctx,
|
2019-02-26 22:32:50 +02:00
|
|
|
cdpDriver,
|
2018-12-01 02:30:55 +02:00
|
|
|
)
|
|
|
|
|
2019-02-26 22:32:50 +02:00
|
|
|
return context.WithCancel(ctx)
|
2018-12-01 02:30:55 +02:00
|
|
|
}
|