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"
|
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
|
|
|
|
2018-12-21 23:14:41 -05:00
|
|
|
func (opts Options) WithContext(ctx context.Context) (context.Context, error) {
|
|
|
|
var err error
|
|
|
|
|
|
|
|
ctx = drivers.WithDynamic(
|
2018-11-30 19:30:55 -05:00
|
|
|
ctx,
|
2018-12-21 23:14:41 -05:00
|
|
|
cdp.NewDriver(
|
|
|
|
cdp.WithAddress(opts.Cdp),
|
|
|
|
cdp.WithProxy(opts.Proxy),
|
|
|
|
cdp.WithUserAgent(opts.UserAgent),
|
|
|
|
),
|
2018-11-30 19:30:55 -05:00
|
|
|
)
|
|
|
|
|
2018-12-21 23:14:41 -05:00
|
|
|
if err != nil {
|
|
|
|
return ctx, err
|
|
|
|
}
|
|
|
|
|
|
|
|
ctx = drivers.WithStatic(
|
2018-11-30 19:30:55 -05:00
|
|
|
ctx,
|
2018-12-21 23:14:41 -05:00
|
|
|
http.NewDriver(
|
|
|
|
http.WithProxy(opts.Proxy),
|
|
|
|
http.WithUserAgent(opts.UserAgent),
|
|
|
|
),
|
2018-11-30 19:30:55 -05:00
|
|
|
)
|
|
|
|
|
2018-12-21 23:14:41 -05:00
|
|
|
return ctx, err
|
2018-11-30 19:30:55 -05:00
|
|
|
}
|