Final Project: Concurrent URL Status Checker
Combine goroutines, channels, structs, and error handling into a small concurrent tool: a URL status checker that checks multiple URLs at once instead of one at a time.
Requirements
- Define a
Resultstruct with fields for the URL, its HTTP status code (or an error), and how long the request took. - Write a
checkURL(url string, results chan<- Result)function usingnet/http'shttp.Get, sending aResultinto the channel when done (success or failure). - In
main, launch a goroutine per URL for a list of at least 5 URLs, then receive and print every result as it arrives. - Handle the error case explicitly, a failed request should still produce a
Result(with the error recorded), not crash the whole program. - Print a final summary: how many succeeded, how many failed, and the total time the whole batch took (it should be close to the slowest single request, not the sum of all of them, that's the entire point of doing this concurrently).
Stretch goals
- Add a timeout per request using
context.WithTimeout. - Limit how many requests run at once (a worker pool) instead of launching unlimited goroutines.
- Sort the final results by response time before printing.
Submit a link to your finished project below, an instructor will review it before you can mark this lesson complete. Good luck!