summaryrefslogtreecommitdiff
path: root/modules/jsonprint/jsonprint.go
diff options
context:
space:
mode:
authorPhilipp Tanlak <philipp.tanlak@gmail.com>2023-12-04 17:35:06 +0100
committerGitHub <noreply@github.com>2023-12-04 17:35:06 +0100
commit8c68e0ed414bfb323d6e94db55c95db13797ef8e (patch)
tree379fd505aec7e54d9f7dcc7b7d6ae5264f4b956a /modules/jsonprint/jsonprint.go
parent807b9a1693645270609d4d795aa2b8eeacaae40e (diff)
Make output file and format configurable (#24)
Diffstat (limited to 'modules/jsonprint/jsonprint.go')
-rw-r--r--modules/jsonprint/jsonprint.go69
1 files changed, 0 insertions, 69 deletions
diff --git a/modules/jsonprint/jsonprint.go b/modules/jsonprint/jsonprint.go
deleted file mode 100644
index c40a8b9..0000000
--- a/modules/jsonprint/jsonprint.go
+++ /dev/null
@@ -1,69 +0,0 @@
-// This Source Code Form is subject to the terms of the Mozilla Public
-// License, v. 2.0. If a copy of the MPL was not distributed with this
-// file, You can obtain one at http://mozilla.org/MPL/2.0/.
-
-package jsonprint
-
-import (
- "fmt"
- "time"
-
- "github.com/philippta/flyscrape"
-)
-
-func init() {
- flyscrape.RegisterModule(Module{})
-}
-
-type Module struct {
- once bool
-}
-
-func (Module) ModuleInfo() flyscrape.ModuleInfo {
- return flyscrape.ModuleInfo{
- ID: "jsonprint",
- New: func() flyscrape.Module { return new(Module) },
- }
-}
-
-func (m *Module) ReceiveResponse(resp *flyscrape.Response) {
- if resp.Error == nil && resp.Data == nil {
- return
- }
-
- if !m.once {
- fmt.Println("[")
- m.once = true
- } else {
- fmt.Println(",")
- }
-
- o := output{
- URL: resp.Request.URL,
- Data: resp.Data,
- Timestamp: time.Now(),
- }
- if resp.Error != nil {
- o.Error = resp.Error.Error()
- }
-
- fmt.Print(flyscrape.Prettify(o, " "))
-}
-
-func (m *Module) Finalize() {
- if m.once {
- fmt.Println("\n]")
- }
-}
-
-type output struct {
- URL string `json:"url,omitempty"`
- Data any `json:"data,omitempty"`
- Error string `json:"error,omitempty"`
- Timestamp time.Time `json:"timestamp,omitempty"`
-}
-
-var (
- _ flyscrape.ResponseReceiver = (*Module)(nil)
- _ flyscrape.Finalizer = (*Module)(nil)
-)