about summary refs log tree commit diff
path: root/src/printer.go
blob: 83268bcc1d88ee8de59d8e4d076830f5aae9ce84 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
package main

import (
	"fmt"
	"log"
)

// printResponse reads a response from the printChannel, formats it and prints it
func printResponses(channels channels) {
	var i int
	for {
		// read a response from the printChannel for further usage
		response := <-channels.printChannel

		// define a postfix: a string attached to the end of all printed
		// string set in the section filtering the status code cases
		var postfix string
		var prefix string

		// define what color should be used to print the individual status
		// codes
		var statusCode string

		switch response.StatusCode {
		case 200:

			// jump to the beginning of the line, clear the line, then print
			// the response
			prefix = "\r\033[K"
			statusCode = green(fmt.Sprintf("%d", response.StatusCode))
			postfix = "\n"

		case 404:

			// print the status code, then clear the line and jump back to
			// the beginning
			statusCode = red(fmt.Sprintf("%d", response.StatusCode))
			postfix = "\033[K\r"

		}

		// print the foo
		fmt.Printf("%s%.7d:   %s    %s%s", prefix, i, statusCode, response.FuzzWord, postfix)
		i++
	}
	log.Printf("%s Done printing the responses", green("[+]"))
}