From 4092f55dcf7634bf0f3e76bdecfbebd6f79b5fa5 Mon Sep 17 00:00:00 2001 From: edoardottt Date: Sun, 12 May 2024 12:36:54 +0200 Subject: [PATCH] Support for JSON output #226 --- pkg/csprecon/csprecon.go | 6 +++--- pkg/output/json.go | 3 ++- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/pkg/csprecon/csprecon.go b/pkg/csprecon/csprecon.go index 9746c4c..9db7f7e 100644 --- a/pkg/csprecon/csprecon.go +++ b/pkg/csprecon/csprecon.go @@ -166,7 +166,7 @@ func execute(r *Runner) { tempResult := []string{} for _, res := range result { - if domainOk(res, r.Options.Domain) { + if DomainOk(res, r.Options.Domain) { tempResult = append(tempResult, res) } } @@ -178,7 +178,7 @@ func execute(r *Runner) { for _, res := range result { if resTrimmed := strings.TrimSpace(res); resTrimmed != "" { if len(r.Options.Domain) != 0 { - if domainOk(resTrimmed, r.Options.Domain) { + if DomainOk(resTrimmed, r.Options.Domain) { r.Output <- resTrimmed } } else { @@ -262,7 +262,7 @@ func writeJSONOutput(wg *sync.WaitGroup, m *sync.Mutex, options *input.Options, m.Lock() if options.Output != nil { - if _, err := options.Output.Write(out); err != nil && options.Verbose { + if _, err := options.Output.Write(append(out, byte('\n'))); err != nil && options.Verbose { gologger.Fatal().Msg(err.Error()) } } diff --git a/pkg/output/json.go b/pkg/output/json.go index 17d3e6c..3d509b0 100644 --- a/pkg/output/json.go +++ b/pkg/output/json.go @@ -39,6 +39,7 @@ func FormatJSON(url string, result []string) ([]byte, error) { return jsonOutput, nil } +// PrepareJSONOutput returns the target URL and the findings. func PrepareJSONOutput(out []string) (url string, result []string, err error) { if len(out) == 0 { return "", []string{}, ErrEmptyResult @@ -47,6 +48,6 @@ func PrepareJSONOutput(out []string) (url string, result []string, err error) { if len(out) == 1 { return out[len(out)-1], []string{}, nil } else { - return out[len(out)-1], out[0 : len(out)-2], nil + return out[len(out)-1], out[0 : len(out)-1], nil } }