Skip to content

Commit

Permalink
Merge branch 'master' into feature/#236-cookies
Browse files Browse the repository at this point in the history
  • Loading branch information
ziflex committed Feb 26, 2019
2 parents 985cd3f + b702f12 commit c38ada9
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 37 deletions.
13 changes: 2 additions & 11 deletions cli/exec.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (
"io/ioutil"
"os"
"os/signal"
"syscall"
)

func ExecFile(pathToFile string, opts Options) {
Expand Down Expand Up @@ -38,18 +37,10 @@ func Exec(query string, opts Options) {

l := NewLogger()

ctx, err := opts.WithContext(context.Background())
ctx, cancel := opts.WithContext(context.Background())

if err != nil {
fmt.Println("Failed to register HTML drivers")
fmt.Println(err)
os.Exit(1)
return
}

ctx, cancel := context.WithCancel(ctx)
c := make(chan os.Signal, 1)
signal.Notify(c, syscall.SIGHUP)
signal.Notify(c, os.Interrupt)

go func() {
for {
Expand Down
26 changes: 15 additions & 11 deletions cli/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,24 +16,28 @@ type Options struct {
ShowTime bool
}

func (opts Options) WithContext(ctx context.Context) (context.Context, error) {
func (opts Options) WithContext(ctx context.Context) (context.Context, context.CancelFunc) {
httpDriver := http.NewDriver(
http.WithProxy(opts.Proxy),
http.WithUserAgent(opts.UserAgent),
)

ctx = drivers.WithContext(
ctx,
http.NewDriver(
http.WithProxy(opts.Proxy),
http.WithUserAgent(opts.UserAgent),
),
httpDriver,
drivers.AsDefault(),
)

cdpDriver := cdp.NewDriver(
cdp.WithAddress(opts.Cdp),
cdp.WithProxy(opts.Proxy),
cdp.WithUserAgent(opts.UserAgent),
)

ctx = drivers.WithContext(
ctx,
cdp.NewDriver(
cdp.WithAddress(opts.Cdp),
cdp.WithProxy(opts.Proxy),
cdp.WithUserAgent(opts.UserAgent),
),
cdpDriver,
)

return ctx, nil
return context.WithCancel(ctx)
}
16 changes: 3 additions & 13 deletions cli/repl.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,10 @@ package cli
import (
"context"
"fmt"
"github.com/MontFerret/ferret/pkg/parser/fql"
"os"
"os/signal"
"strings"
"syscall"

"github.com/MontFerret/ferret/pkg/parser/fql"

"github.com/MontFerret/ferret/pkg/compiler"
"github.com/MontFerret/ferret/pkg/runtime"
Expand Down Expand Up @@ -50,18 +48,10 @@ func Repl(version string, opts Options) {

l := NewLogger()

ctx, err := opts.WithContext(context.Background())

if err != nil {
fmt.Println("Failed to register HTML drivers")
fmt.Println(err)
os.Exit(1)
return
}
ctx, cancel := opts.WithContext(context.Background())

ctx, cancel := context.WithCancel(ctx)
c := make(chan os.Signal, 1)
signal.Notify(c, syscall.SIGHUP)
signal.Notify(c, os.Interrupt)

exit := func() {
cancel()
Expand Down
6 changes: 4 additions & 2 deletions pkg/runtime/program.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@ package runtime

import (
"context"
"runtime"

"github.com/MontFerret/ferret/pkg/runtime/core"
"github.com/MontFerret/ferret/pkg/runtime/logging"
"github.com/MontFerret/ferret/pkg/runtime/values"
"github.com/pkg/errors"
"runtime"
)

type Program struct {
Expand Down Expand Up @@ -61,12 +62,13 @@ func (p *Program) Run(ctx context.Context, setters ...Option) (result []byte, er
}()

scope, closeFn := core.NewRootScope()

defer func() {
if err := closeFn(); err != nil {
logger.Error().
Timestamp().
Err(err).
Msg("Closing root scope")
Msg("closing root scope")
}
}()

Expand Down

0 comments on commit c38ada9

Please sign in to comment.