Skip to content

Commit

Permalink
Update callback calling place
Browse files Browse the repository at this point in the history
- Callback for every result, even it contains error
- User can handle it using Result.Err
  • Loading branch information
ShubhamRasal committed May 19, 2023
1 parent addddf1 commit bc7ac8d
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 6 deletions.
11 changes: 10 additions & 1 deletion examples/example.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package main

import (
"fmt"
"log"

"github.com/projectdiscovery/goflags"
Expand All @@ -14,8 +15,16 @@ func main() {

options := runner.Options{
Methods: "GET",
InputTargetHost: goflags.StringSlice{"scanme.sh", "projectdiscovery.io"},
InputTargetHost: goflags.StringSlice{"scanme.sh", "projectdiscovery.io", "localhost"},
//InputFile: "./targetDomains.txt", // path to file containing the target domains list
OnResult: func(r runner.Result) {
// handle error
if r.Err != nil {
fmt.Printf("[Err] %s: %s\n", r.Input, r.Err)
return
}
fmt.Printf("%s %s %d\n", r.Input, r.Host, r.StatusCode)
},
}

if err := options.ValidateOptions(); err != nil {
Expand Down
11 changes: 6 additions & 5 deletions runner/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -262,11 +262,12 @@ type Options struct {
ListDSLVariable bool
OutputFilterCondition string
OutputMatchCondition string
OnResult OnResultCallback
DisableUpdateCheck bool
NoDecode bool
Screenshot bool
UseInstalledChrome bool
//The OnResult callback function is invoked for each result. It is important to check for errors in the result before using Result.Err.
OnResult OnResultCallback
DisableUpdateCheck bool
NoDecode bool
Screenshot bool
UseInstalledChrome bool
}

// ParseOptions parses the command line options for application
Expand Down
7 changes: 7 additions & 0 deletions runner/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -663,6 +663,13 @@ func (r *Runner) RunEnumeration() {
}

for resp := range output {

// call the callback function if any
// be careful and check for result.Err
if r.options.OnResult != nil {
r.options.OnResult(resp)
}

if resp.Err != nil {
// Change the error message if any port value passed explicitly
if url, err := r.parseURL(resp.URL); err == nil && url.Port() != "" {
Expand Down

0 comments on commit bc7ac8d

Please sign in to comment.