2018-09-25 21:49:42 -04:00
|
|
|
package cli
|
2018-09-23 02:05:05 -04:00
|
|
|
|
2018-11-30 19:30:55 -05:00
|
|
|
import (
|
|
|
|
"context"
|
2019-02-19 18:10:18 -05:00
|
|
|
|
2018-12-21 23:14:41 -05:00
|
|
|
"github.com/MontFerret/ferret/pkg/drivers"
|
|
|
|
"github.com/MontFerret/ferret/pkg/drivers/cdp"
|
|
|
|
"github.com/MontFerret/ferret/pkg/drivers/http"
|
2018-11-30 19:30:55 -05:00
|
|
|
)
|
|
|
|
|
2018-09-23 02:05:05 -04:00
|
|
|
type Options struct {
|
2018-10-07 22:18:57 -04:00
|
|
|
Cdp string
|
|
|
|
Params map[string]interface{}
|
|
|
|
Proxy string
|
|
|
|
UserAgent string
|
2018-10-11 12:39:03 -04:00
|
|
|
ShowTime bool
|
2018-09-23 02:05:05 -04:00
|
|
|
}
|
2018-11-30 19:30:55 -05:00
|
|
|
|
2019-02-26 15:32:50 -05: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-19 18:10:18 -05:00
|
|
|
ctx = drivers.WithContext(
|
|
|
|
ctx,
|
2019-02-26 15:32:50 -05:00
|
|
|
httpDriver,
|
2019-02-19 18:10:18 -05:00
|
|
|
drivers.AsDefault(),
|
|
|
|
)
|
2018-12-21 23:14:41 -05:00
|
|
|
|
2019-02-26 15:32:50 -05:00
|
|
|
cdpDriver := cdp.NewDriver(
|
|
|
|
cdp.WithAddress(opts.Cdp),
|
|
|
|
cdp.WithProxy(opts.Proxy),
|
|
|
|
cdp.WithUserAgent(opts.UserAgent),
|
|
|
|
)
|
|
|
|
|
2019-02-19 18:10:18 -05:00
|
|
|
ctx = drivers.WithContext(
|
2018-11-30 19:30:55 -05:00
|
|
|
ctx,
|
2019-02-26 15:32:50 -05:00
|
|
|
cdpDriver,
|
2018-11-30 19:30:55 -05:00
|
|
|
)
|
|
|
|
|
2019-02-26 15:32:50 -05:00
|
|
|
return context.WithCancel(ctx)
|
2018-11-30 19:30:55 -05:00
|
|
|
}
|