URL Status Checker
Build a command-line tool in Go that checks whether a list of websites is up. It reads URLs from a text file, checks them all at the same time, and prints a table with each URL's HTTP status code, response time, and any error, for example a timeout or a DNS failure. It can also check gRPC services using the standard gRPC health-check protocol. It's a friendly introduction to what makes Go special: goroutines and channels for doing many things at once, plus timeouts, error handling and clean output.
- Estimate
- ~9.5h
- Steps
- 6
- Completed by
- 0
- Proposed by
- codeseed.app
net/http · gRPC
Project roadmap
- 01
Read the URL list
~1hRun go mod init and write a program that takes a file path as its argument and reads it line by line with bufio.Scanner. Skip empty lines and lines starting with #, and check each line is a valid http or https URL with net/url. Print invalid lines as warnings and exit with code 2 if the file can't be opened. Done when: the program prints the valid URLs from a sample urls.txt in the repo.
- 02
Check one URL
~1.5hWrite a function check(url string) Result that sends a GET request with an http.Client that has a 5-second timeout, and measures the response time with time.Now and time.Since. Result holds the URL, the status code, the duration and an error, if any. Close the response body every time. Done when: checking a working site and a non-existent domain returns a status and an error respectively.
- 03
Check all URLs concurrently
~2hStart a goroutine for each URL and send each Result into a channel. Limit the number of checks running at once to 10, using a buffered channel as a semaphore, and use a sync.WaitGroup to know when all are done. Done when: checking 20 URLs takes about as long as the slowest one, not the sum of all of them.
- 04
Print a results table
~1.5hCollect the results and print a table aligned with text/tabwriter, with URL, status, time in ms and error. Sort it by URL so the output is stable, and finish with a summary like 18 up, 2 down. Exit with code 1 if any check failed or returned a status of 400 or higher. Done when: the table is aligned and the exit code reflects failures.
- 05
Check gRPC services
~2hLines starting with grpc://host:port are gRPC services. For these, connect with google.golang.org/grpc and call the standard health check (the grpc_health_v1 Health service's Check method) with a 5-second timeout, and report SERVING or the error in the same table. Add a sample gRPC entry to urls.txt. Done when: gRPC lines are checked and appear in the table alongside the websites.
- 06
Add tests
~1.5hWrite tests using net/http/httptest to start fake servers: one that returns 200, one that returns 500, and one that sleeps longer than the timeout. Check that the results have the right status, error and timing. Done when: go test ./... passes.
Resources
Ready to build this?
Get a GitHub repo and start building. Your AI reviewer checks each step as you go.
Tech stack