From 3bd9baca5b0b97ec309aa5cf5dc0c88e0841661a Mon Sep 17 00:00:00 2001 From: Emile Date: Sat, 2 Nov 2019 22:11:36 +0100 Subject: using the channels struct --- src/httpRequest.go | 33 +++++++++++++++++---------------- 1 file changed, 17 insertions(+), 16 deletions(-) (limited to 'src') 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) } } -- cgit 1.4.1