From 1190174edda07fea3f956b58a782eaff2d2213b8 Mon Sep 17 00:00:00 2001 From: demo Date: Wed, 27 May 2026 11:56:57 -0400 Subject: refactor: move "packet conversion" into a separate function --- workers.go | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/workers.go b/workers.go index 535e50c..43e398d 100644 --- a/workers.go +++ b/workers.go @@ -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 +} -- cgit v1.2.3