for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
package producer
import (
"path"
"sync"
"github.com/stefanoj3/dirstalk/pkg/pathutil"
"github.com/stefanoj3/dirstalk/pkg/scan"
)
const defaultChannelBuffer = 25
var statusCodesToSkip = map[int]bool{
404: false,
}
func NewReProducer(
producer scan.Producer,
) *ReProducer {
return &ReProducer{
producer: producer,
type ReProducer struct {
producer scan.Producer
// Reproduce will check if it is possible to go deeper on the result provided, if so will
func (r *ReProducer) Reproduce() func(r scan.Result) <-chan scan.Target {
return r.buildReproducer()
func (r *ReProducer) buildReproducer() func(result scan.Result) <-chan scan.Target {
resultRegistry := sync.Map{}
return func(result scan.Result) <-chan scan.Target {
resultChannel := make(chan scan.Target, defaultChannelBuffer)
go func() {
defer close(resultChannel)
if _, ok := statusCodesToSkip[result.Response.StatusCode]; ok {
return
if result.Target.Depth <= 0 {
// no point in appending to a filename
if pathutil.HasExtension(result.Target.Path) {
_, inRegistry := resultRegistry.Load(result.Target.Path)
if inRegistry {
resultRegistry.Store(result.Target.Path, false)
for target := range r.producer.Produce() {
newTarget := result.Target
newTarget.Depth--
newTarget.Path = path.Join(newTarget.Path, target.Path)
newTarget.Method = target.Method
resultChannel <- newTarget
}()
return resultChannel