Projects STRLCPY csprecon Commits b7e0625c
🤬
  • ■ ■ ■ ■ ■ ■
    pkg/csprecon/csprecon.go
    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   
  • ■ ■ ■ ■ ■
    pkg/output/output.go
    skipped 4 lines
    5 5  )
    6 6   
    7 7  type Result struct {
    8  - Map sync.Map
     8 + Map map[string]struct{}
     9 + Mutex sync.RWMutex
    9 10  }
    10 11   
    11 12  func New() Result {
    12  - return Result{Map: sync.Map{}}
     13 + return Result{
     14 + Map: map[string]struct{}{},
     15 + Mutex: sync.RWMutex{},
     16 + }
    13 17  }
    14 18   
    15 19  func (o *Result) Printed(result string) bool {
    16  - if _, ok := o.Map.Load(result); !ok {
    17  - o.Map.Store(result, true)
     20 + o.Mutex.RLock()
     21 + if _, ok := o.Map[result]; !ok {
     22 + o.Mutex.RUnlock()
     23 + o.Mutex.Lock()
     24 + o.Map[result] = struct{}{}
     25 + o.Mutex.Unlock()
    18 26   return false
     27 + } else {
     28 + o.Mutex.RUnlock()
    19 29   }
    20 30   
    21 31   return true
    skipped 2 lines
Please wait...
Page is in error, reload to recover