This is a simple health check service implemented in Go. It makes HTTP requests to URLs configured in an environment variable and checks the response status of each. The service runs continuously, checking the URLs at regular intervals (configured in the code).
URLs that return a 200 (OK) status are logged as successful, and URLs that return other statuses or connection errors are logged as failures.
- Checks the health of multiple services via HTTP.
- Logs the results to the terminal, using colors to indicate success or failure:
- Green for success (status 200).
- Red for errors or statuses other than 200.
- Continuous loop to check the URLs every 30 seconds (configurable).
Before running the project, make sure you have the following installed:
git clone https://github.com/yourusername/health-track.git
cd health-track
The service uses an environment variable called CHECK_URLS
to determine which URLs to check. Create a .env
file in the root of the project with the following content:
CHECK_URLS=http://example.com/health,http://example2.com/health
Important: Separate the URLs with a comma and do not include spaces between them.
Run the following command to install the Go dependencies defined in the go.mod
file:
go mod tidy
Once the dependencies are installed, you can start the service with the following command:
go run main.go
This will start the health check service, which will check the URLs defined in the .env
file every 30 seconds and print the results to the terminal.
In the main.go
file, you can adjust the time interval between checks by modifying the line that contains time.Sleep(30 * time.Second)
.
Example to run the health check every 60 seconds:
time.Sleep(60 * time.Second)
├── .env # Environment file with URLs to check
├── main.go # Main service code
├── go.mod # Go module file
├── go.sum # Go module dependency checksums
└── README.md # This file
This project is licensed under the MIT License. See the LICENSE file for details.