Skip to content

Commit 9b5140f

Browse files
committed
Separate concurrency and busienss logic
1 parent 17a4fa3 commit 9b5140f

File tree

1 file changed

+11
-11
lines changed

1 file changed

+11
-11
lines changed

internal/unsavory/unsavory.go

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,16 @@ func (c *Client) checkURLs(urls []string) {
8080
ch := make(chan string)
8181

8282
for i := 0; i < workerCount; i++ {
83-
go c.checkURL(ch)
83+
go func(urls chan string) {
84+
for {
85+
u, ok := <-urls
86+
if !ok {
87+
break
88+
}
89+
90+
c.checkURL(u)
91+
}
92+
}(ch)
8493
}
8594

8695
for _, url := range urls {
@@ -89,13 +98,7 @@ func (c *Client) checkURLs(urls []string) {
8998
close(ch)
9099
}
91100

92-
func (c *Client) checkURL(urls chan string) {
93-
for {
94-
u, ok := <-urls
95-
if !ok {
96-
return
97-
}
98-
101+
func (c *Client) checkURL(u string) {
99102
resp, err := c.client.Head(u)
100103
if err != nil {
101104
if _, ok := err.(*url.Error); ok {
@@ -104,8 +107,6 @@ func (c *Client) checkURL(urls chan string) {
104107
}
105108
} else {
106109
switch resp.StatusCode {
107-
case http.StatusOK:
108-
continue
109110
case http.StatusNotFound, http.StatusGone:
110111
log.Printf("Deleting (404): %s\n", u)
111112
c.deleteURL(u)
@@ -114,7 +115,6 @@ func (c *Client) checkURL(urls chan string) {
114115
}
115116
}
116117
}
117-
}
118118

119119
func (c *Client) deleteURL(url string) {
120120
if !c.DryRun {

0 commit comments

Comments
 (0)