Go Fundamentals

Lesson 8 of 8

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

  1. Define a Result struct with fields for the URL, its HTTP status code (or an error), and how long the request took.
  2. Write a checkURL(url string, results chan<- Result) function using net/http's http.Get, sending a Result into the channel when done (success or failure).
  3. In main, launch a goroutine per URL for a list of at least 5 URLs, then receive and print every result as it arrives.
  4. Handle the error case explicitly, a failed request should still produce a Result (with the error recorded), not crash the whole program.
  5. 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!

This lesson ends in a project. Build it on your own machine, there's nowhere to submit it here, but the brief above is everything you need.