MCPcopy Create free account
hub / github.com/003random/getJS / ProcessURLs

Method ProcessURLs

runner/runner.go:85–142  ·  view source on GitHub ↗

ProcessURLs will fetch the HTTP response for all URLs in the provided reader and stream the extracted sources to the runner's Results channel.

(data io.Reader)

Source from the content-addressed store, hash-verified

83// ProcessURLs will fetch the HTTP response for all URLs in the provided reader
84// and stream the extracted sources to the runner's Results channel.
85func (r *runner) ProcessURLs(data io.Reader) {
86 var (
87 next = Read(data)
88 wg = sync.WaitGroup{}
89
90 throttle = make(chan struct{}, r.Options.Threads)
91 )
92
93 for i := 0; i < r.Options.Threads; i++ {
94 throttle <- struct{}{}
95 }
96
97 for {
98 u, err := next()
99 if errors.Is(err, io.EOF) {
100 break
101 }
102 if err != nil {
103 log.Println(fmt.Errorf("[error] parsing url %v: %w", u, err))
104 continue
105 }
106
107 wg.Add(1)
108 go func(u *url.URL) {
109 defer func() {
110 throttle <- struct{}{}
111 wg.Done()
112 }()
113
114 resp, err := extractor.FetchResponse(u.String(), r.Options.Request.Method, r.Options.Request.Headers)
115 if err != nil {
116 log.Println(fmt.Errorf("[error] fetching response for url %s: %w", u.String(), err))
117 return
118 }
119 defer resp.Body.Close()
120
121 sources, err := extractor.ExtractSources(resp.Body)
122 if err != nil {
123 log.Println(fmt.Errorf("[error] extracting sources from response for url %s: %w", u.String(), err))
124 return
125 }
126
127 filtered, err := extractor.Filter(sources, r.filters(u)...)
128 if err != nil {
129 log.Println(fmt.Errorf("[error] filtering sources for url %s: %w", u.String(), err))
130 return
131 }
132
133 for source := range filtered {
134 r.Results <- source
135 }
136 }(u)
137
138 <-throttle
139 }
140
141 wg.Wait()
142}

Callers 1

RunMethod · 0.95

Calls 6

filtersMethod · 0.95
FetchResponseFunction · 0.92
ExtractSourcesFunction · 0.92
FilterFunction · 0.92
ReadFunction · 0.85
StringMethod · 0.80

Tested by

no test coverage detected