| skipped 17 lines |
18 | 18 | | type Runner struct { |
19 | 19 | | Input chan string |
20 | 20 | | Output chan string |
| 21 | + | Result output.Result |
21 | 22 | | InWg *sync.WaitGroup |
22 | 23 | | OutWg *sync.WaitGroup |
23 | 24 | | Options input.Options |
| skipped 3 lines |
27 | 28 | | return Runner{ |
28 | 29 | | Input: make(chan string, options.Concurrency), |
29 | 30 | | Output: make(chan string, options.Concurrency), |
| 31 | + | Result: output.New(), |
30 | 32 | | InWg: &sync.WaitGroup{}, |
31 | 33 | | OutWg: &sync.WaitGroup{}, |
32 | 34 | | Options: *options, |
| skipped 87 lines |
120 | 122 | | func pullOutput(r *Runner) { |
121 | 123 | | defer r.OutWg.Done() |
122 | 124 | | |
123 | | - | out := output.New() |
124 | | - | |
125 | 125 | | for o := range r.Output { |
126 | | - | r.OutWg.Add(1) |
| 126 | + | if !r.Result.Printed(o) { |
| 127 | + | r.OutWg.Add(1) |
127 | 128 | | |
128 | | - | go writeOutput(r.OutWg, &r.Options, &out, o) |
| 129 | + | go writeOutput(r.OutWg, &r.Options, &r.Result, o) |
| 130 | + | } |
129 | 131 | | } |
130 | 132 | | } |
131 | 133 | | |
132 | 134 | | func writeOutput(wg *sync.WaitGroup, options *input.Options, out *output.Result, o string) { |
133 | 135 | | defer wg.Done() |
134 | 136 | | |
135 | | - | if options.FileOutput != "" { |
| 137 | + | if options.FileOutput != "" && options.Output == nil { |
136 | 138 | | file, err := os.OpenFile(options.FileOutput, os.O_CREATE|os.O_RDWR|os.O_APPEND, 0644) |
137 | 139 | | if err != nil { |
138 | 140 | | gologger.Fatal().Msg(err.Error()) |
| skipped 2 lines |
141 | 143 | | options.Output = file |
142 | 144 | | } |
143 | 145 | | |
144 | | - | if !out.Printed(o) { |
145 | | - | if options.Output != nil { |
146 | | - | if _, err := options.Output.Write([]byte(o + "\n")); err != nil && options.Verbose { |
147 | | - | gologger.Fatal().Msg(err.Error()) |
148 | | - | } |
| 146 | + | if options.Output != nil { |
| 147 | + | if _, err := options.Output.Write([]byte(o + "\n")); err != nil && options.Verbose { |
| 148 | + | gologger.Fatal().Msg(err.Error()) |
149 | 149 | | } |
| 150 | + | } |
| 151 | + | |
| 152 | + | fmt.Println(o) |
150 | 153 | | |
151 | | - | fmt.Println(o) |
152 | | - | } |
153 | 154 | | } |
154 | 155 | | |