diff options
| author | demo <demo@antix1> | 2026-05-27 11:56:57 -0400 |
|---|---|---|
| committer | demo <demo@antix1> | 2026-05-27 11:56:57 -0400 |
| commit | 1190174edda07fea3f956b58a782eaff2d2213b8 (patch) | |
| tree | 0e477ce966b780a9be3d413a53b192390e4a658a | |
| parent | 26f5b43a82955c77ea4bc1d7a710895e4b36209a (diff) | |
refactor: move "packet conversion" into a separate function
| -rw-r--r-- | workers.go | 20 |
1 files changed, 14 insertions, 6 deletions
@@ -54,12 +54,7 @@ func workers(startURL url.URL, maxConcurrency, maxURLs int) { // Convert URLs to Packets. In the // process, bump up the depth by 1. - var ps []Packet - - for _, u := range batch { - newPacket := Packet{u, p.depth + 1} - ps = append(ps, newPacket) - } + ps := convertToPackets(batch, p.depth+1) select { case <-ctx.Done(): @@ -110,3 +105,16 @@ loop: cancel() wg.Wait() } + +// convertToPackets converts the batch of URLs to a slice of Packet +// structs, configuring each one with the given depth. +func convertToPackets(batch []url.URL, depth int) []Packet { + var ps []Packet + + for _, u := range batch { + newPacket := Packet{u, depth} + ps = append(ps, newPacket) + } + + return ps +} |
