This is a program in GO that makes multiple HTTP GET requests taking the URLs from a text file. The multiple requests are made concurrently using Goroutines.
Open your favorite Terminal and run this command:
go run main.go
The program can be run with the following options:
Usage of multirequest:
-f string
File path (default "urls.txt")
-h string
for example:
go run main.go -f "./my_other_urls.txt"
or for example on Windows using the executable:
multirequest.exe -f "./my_other_urls.txt"
In case you made it, you should see something like this:
go test -v ./...
The client_test.go file contains the tests for the client.go file. Mocks valid and invalid http response, generated by using httptest.
The scanner_test.go file contains the tests for the scanner.go file. Tests the reading of the file and the parsing of the urls.
Both are tested using table driven tests.
client and scanner files are fully covered 100% by tests.
you can check the coverage by running:
go test -cover ./...
A code coverage summary is visilbe in the cover.html file.
Some files are not covered by tests, this is because they are not part of the core logic of the program.
go build
The github actions are defined in the test.yml file. The actions are triggered on every push, testing and building the code.
The results of each http connection and user action, with the timestamp of the http response code, are written into a JSONL file. This kind of format is useful for streaming data, and it is also easy to parse. It is possible to check some example logs in the example_logs_result folder.
Logging is handled by using Zerolog that has the best performance in the Go envirovment
Mock HTTP responses are generated by using httptest
The solution is dockerized by using Docker. Build a Docker image named multirequest based on the instructions in the Dockerfile:
docker build -t multirequest .
Use the docker run command to start a Docker container from the image:
docker run -p 8080:8080 multirequest
Thanks goes to these wonderful people, just me for now:
Lorenzo Zaccagnini 💬 📖 |