MCPcopy
hub / github.com/OJ/gobuster / resultWorker

Function resultWorker

cli/gobuster.go:23–57  ·  view source on GitHub ↗

resultWorker outputs the results as they come in. This needs to be a range and should not handle the context so the channel always has a receiver and libgobuster will not block.

(g *libgobuster.Gobuster, filename string, wg *sync.WaitGroup)

Source from the content-addressed store, hash-verified

21// resultWorker outputs the results as they come in. This needs to be a range and should not handle
22// the context so the channel always has a receiver and libgobuster will not block.
23func resultWorker(g *libgobuster.Gobuster, filename string, wg *sync.WaitGroup) {
24 defer wg.Done()
25
26 var f *os.File
27 var err error
28 if filename != "" {
29 f, err = os.Create(filename)
30 if err != nil {
31 g.Logger.Fatalf("error on creating output file: %v", err)
32 }
33 defer f.Close()
34 }
35
36 for r := range g.Progress.ResultChan {
37 s, err := r.ResultToString()
38 if err != nil {
39 g.Logger.Fatal(err)
40 }
41 if s != "" {
42 s = strings.TrimSpace(s)
43 if g.Opts.NoProgress || g.Opts.Quiet {
44 _, _ = fmt.Printf("%s\n", s) // nolint forbidigo
45 } else {
46 // only print the clear line when progress output is enabled
47 _, _ = fmt.Printf("%s%s\n", TerminalClearLine, s) // nolint forbidigo
48 }
49 if f != nil {
50 err = writeToFile(f, s)
51 if err != nil {
52 g.Logger.Fatalf("error on writing output file: %v", err)
53 }
54 }
55 }
56 }
57}
58
59// errorWorker outputs the errors as they come in. This needs to be a range and should not handle
60// the context so the channel always has a receiver and libgobuster will not block.

Callers 1

GobusterFunction · 0.85

Calls 5

writeToFileFunction · 0.85
FatalfMethod · 0.80
FatalMethod · 0.80
PrintfMethod · 0.80
ResultToStringMethod · 0.65

Tested by

no test coverage detected