pkg/scan/producer/dictionary.go   A
last analyzed

Size/Duplication

Total Lines 49
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
cc 7
eloc 32
dl 0
loc 49
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
B producer.*DictionaryProducer.Produce 0 23 6
A producer.NewDictionaryProducer 0 9 1
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