about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/httpRequest.go33
1 files changed, 17 insertions, 16 deletions
diff --git a/src/httpRequest.go b/src/httpRequest.go
index 4d1c3d8..139e0a4 100644
--- a/src/httpRequest.go
+++ b/src/httpRequest.go
@@ -7,41 +7,42 @@ import (
 	"strings"
 )
 
-func httpRequest(wordlistChannel chan string, printChannel chan Response, doneChannel chan int, threadNr int) {
+func httpRequest(channels channels, threadNr int) {
 	for {
 		// replace the first instance of "FUZZ" in the given url by the next
 		// value from the wordlistChannel
-		fuzzWord := <-wordlistChannel
+		fuzzWord := <-channels.wordlistChannel
 		requestURL := strings.Replace(url, "FUZZ", fuzzWord, 1)
 
 		// make the http get request
 		resp, err := http.Get("https://" + requestURL)
 		if err != nil {
 			log.Println(err)
-		}
+		} else {
+			// define the response
+			var response = Response{
+				StatusCode: resp.StatusCode,
+				FuzzWord:   fuzzWord,
+			}
 
-		// define the response
-		var response = Response{
-			StatusCode: resp.StatusCode,
-			FuzzWord:   fuzzWord,
+			// insert the response into the print channel for further printing
+			channels.printChannel <- response
 		}
-
-		// insert the response into the print channel for further printing
-		printChannel <- response
 	}
 
-	if doneChannel != nil {
-		doneChannel <- threadNr
+	if channels.doneChannel != nil {
+		channels.doneChannel <- threadNr
 	}
 }
 
-func httpHandler(wordlistChannel chan string, printChannel chan Response, doneChannel chan int) {
+func httpHandler(channels channels) {
 	log.Printf("%s Starting the http handlers", green("[i]"))
 
 	// handle one or more theads
 	if threads <= 1 {
 		log.Printf("%s 1 thread", yellow("[i]"))
-		httpRequest(wordlistChannel, printChannel, nil, 0)
+		httpRequest(channels, 0)
+
 	} else {
 		log.Printf("%s Starting %d threads...", yellow("[i]"), threads)
 
@@ -49,12 +50,12 @@ func httpHandler(wordlistChannel chan string, printChannel chan Response, doneCh
 		// the wordlistChannel, making the request and inserting the result into
 		// the printChannel
 		for i := 0; i < threads; i++ {
-			go httpRequest(wordlistChannel, printChannel, doneChannel, i)
+			go httpRequest(channels, i)
 		}
 		log.Printf("%s Done starting %d threads", green("[i]"), threads)
 
 		for i := 0; i < threads; i++ {
-			threadNum := <-doneChannel
+			threadNum := <-channels.doneChannel
 			fmt.Printf("Thread %d done!\n", threadNum)
 		}
 	}