diff options
author | Emile <hanemile@protonmail.com> | 2019-11-02 22:11:36 +0100 |
---|---|---|
committer | Emile <hanemile@protonmail.com> | 2019-11-02 22:11:36 +0100 |
commit | 3bd9baca5b0b97ec309aa5cf5dc0c88e0841661a (patch) | |
tree | 1bf78f54e33ad882513ca8c40b43d9c24e9e8218 /src | |
parent | 17dff95d13dcf289cf91821a0e35c485811f7aaa (diff) |
using the channels struct
Diffstat (limited to 'src')
-rw-r--r-- | src/httpRequest.go | 33 |
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) } } |