@@ -113,9 +113,7 @@ func (r *Runner) Run() {
113113 for value := range r .InputChan {
114114 targetURL , err := PrepareURL (value , testPayload )
115115 if err != nil {
116- if r .Options .Verbose {
117- gologger .Error ().Msg (err .Error ())
118- }
116+ verboseOutput (r , value , err )
119117 }
120118
121119 ctx , cancel := context .WithTimeout (pctx , time .Second * time .Duration (r .Options .Timeout ))
@@ -125,13 +123,15 @@ func (r *Runner) Run() {
125123
126124 res , err := Scan (ctx , js , targetURL )
127125 if err != nil {
128- if r .Options .Verbose {
129- gologger .Error ().Msg (err .Error ())
130- }
126+ verboseOutput (r , targetURL , err )
131127 }
132128
133129 if resTrimmed := strings .TrimSpace (res ); resTrimmed != "" {
134- writeOutput (r , targetURL )
130+ if err != nil {
131+ writeOutput (r , targetURL , res , err .Error ())
132+ } else {
133+ writeOutput (r , targetURL , res , "" )
134+ }
135135 }
136136
137137 cancel ()
@@ -146,13 +146,13 @@ func (r *Runner) Run() {
146146 wg .Wait ()
147147}
148148
149- func writeOutput (r * Runner , targetURL string ) {
150- if ! r .Result .Printed (targetURL ) {
151- write (r .OutMutex , & r .Options , targetURL )
149+ func writeOutput (r * Runner , url , jsEval , err string ) {
150+ if ! r .Result .Printed (url ) {
151+ write (r .OutMutex , & r .Options , url , jsEval , err )
152152 }
153153}
154154
155- func write (m * sync.Mutex , options * input.Options , o string ) {
155+ func write (m * sync.Mutex , options * input.Options , u , jse , e string ) {
156156 if options .FileOutput != "" && options .Output == nil {
157157 file , err := os .OpenFile (options .FileOutput , os .O_CREATE | os .O_RDWR | os .O_APPEND , 0644 )
158158 if err != nil {
@@ -162,15 +162,44 @@ func write(m *sync.Mutex, options *input.Options, o string) {
162162 options .Output = file
163163 }
164164
165+ var (
166+ o []byte
167+ err error
168+ )
169+
170+ if options .JSON {
171+ o , err = output .FormatJSON (u , jse , e )
172+ if err != nil {
173+ gologger .Fatal ().Msg (err .Error ())
174+ }
175+ } else {
176+ o = []byte (u )
177+ }
178+
165179 m .Lock ()
166180
167181 if options .Output != nil {
168- if _ , err := options .Output .Write ([]byte (o + "\n " )); err != nil && options .Verbose {
182+ if _ , err := options .Output .Write ([]byte (string ( o ) + "\n " )); err != nil && options .Verbose {
169183 gologger .Fatal ().Msg (err .Error ())
170184 }
171185 }
172186
173187 m .Unlock ()
174188
175- fmt .Println (o )
189+ fmt .Println (string (o ))
190+ }
191+
192+ func verboseOutput (r * Runner , value string , err error ) {
193+ if r .Options .Verbose {
194+ if r .Options .JSON {
195+ o , err := output .FormatJSON (value , "" , err .Error ())
196+ if err != nil {
197+ gologger .Error ().Msg (err .Error ())
198+ }
199+
200+ fmt .Println (string (o ))
201+ } else {
202+ gologger .Error ().Msg (err .Error ())
203+ }
204+ }
176205}
0 commit comments