producer.*DictionaryProducer.Produce   B
last analyzed

Complexity

Conditions 6

Size

Total Lines 23
Code Lines 15

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 6
eloc 15
nop 1
dl 0
loc 23
rs 8.6666
c 0
b 0
f 0
1
package producer
2
3
import (
4
	"context"
5
6
	"github.com/stefanoj3/dirstalk/pkg/scan"
7
)
8
9
func NewDictionaryProducer(
10
	methods []string,
11
	dictionary []string,
12
	depth int,
13
) *DictionaryProducer {
14
	return &DictionaryProducer{
15
		methods:    methods,
16
		dictionary: dictionary,
17
		depth:      depth,
18
	}
19
}
20
21
type DictionaryProducer struct {
22
	methods    []string
23
	dictionary []string
24
	depth      int
25
}
26
27
func (p *DictionaryProducer) Produce(ctx context.Context) <-chan scan.Target {
28
	targets := make(chan scan.Target, 10)
29
30
	go func() {
31
		defer close(targets)
32
33
		for _, entry := range p.dictionary {
34
			for _, method := range p.methods {
35
				select {
36
				case <-ctx.Done():
37
					return
38
				default:
39
					targets <- scan.Target{
40
						Path:   entry,
41
						Method: method,
42
						Depth:  p.depth,
43
					}
44
				}
45
			}
46
		}
47
	}()
48
49
	return targets
50
}
51