diff options
| author | Philipp Tanlak <philipp.tanlak@gmail.com> | 2023-08-27 19:10:49 +0200 |
|---|---|---|
| committer | Philipp Tanlak <philipp.tanlak@gmail.com> | 2023-08-27 19:10:49 +0200 |
| commit | 5c16435e2218344a6e232ebb48cf022a32ba85d5 (patch) | |
| tree | 3cfa1dbc1f489ba4509fc408a8c0afccca7f9c7c /cmd | |
| parent | 52107c13b4c2c4efa9269b187916f3195be5a10d (diff) | |
add tests and allow urls
Diffstat (limited to 'cmd')
| -rw-r--r-- | cmd/flyscrape/run.go | 4 | ||||
| -rw-r--r-- | cmd/flyscrape/watch.go | 10 |
2 files changed, 13 insertions, 1 deletions
diff --git a/cmd/flyscrape/run.go b/cmd/flyscrape/run.go index cf8f8cf..8e83ca8 100644 --- a/cmd/flyscrape/run.go +++ b/cmd/flyscrape/run.go @@ -19,6 +19,7 @@ type RunCommand struct{} func (c *RunCommand) Run(args []string) error { fs := flag.NewFlagSet("flyscrape-run", flag.ContinueOnError) noPrettyPrint := fs.Bool("no-pretty-print", false, "no-pretty-print") + proxy := fs.String("proxy", "", "proxy") fs.Usage = c.Usage if err := fs.Parse(args); err != nil { @@ -44,6 +45,9 @@ func (c *RunCommand) Run(args []string) error { ScrapeOptions: opts, ScrapeFunc: scrape, } + if *proxy != "" { + svc.FetchFunc = flyscrape.ProxiedFetch(*proxy) + } count := 0 start := time.Now() diff --git a/cmd/flyscrape/watch.go b/cmd/flyscrape/watch.go index 02a3b45..777ae8a 100644 --- a/cmd/flyscrape/watch.go +++ b/cmd/flyscrape/watch.go @@ -18,6 +18,7 @@ type WatchCommand struct{} func (c *WatchCommand) Run(args []string) error { fs := flag.NewFlagSet("flyscrape-watch", flag.ContinueOnError) + proxy := fs.String("proxy", "", "proxy") fs.Usage = c.Usage if err := fs.Parse(args); err != nil { @@ -28,7 +29,14 @@ func (c *WatchCommand) Run(args []string) error { return fmt.Errorf("too many arguments") } - fetch := flyscrape.CachedFetch() + var fetch flyscrape.FetchFunc + if *proxy != "" { + fetch = flyscrape.ProxiedFetch(*proxy) + } else { + fetch = flyscrape.Fetch() + } + + fetch = flyscrape.CachedFetch(fetch) script := fs.Arg(0) err := flyscrape.Watch(script, func(s string) error { |