- Go 1.22.5
- PostgreSQL database (docker compose is there too)
- Install dependencies:
go mod tidy
-
Configure the PostgreSQL database connection in
config/db_config.json
:{ "database": { "user": "yourusername", "password": "yourpassword", "dbname": "yourdatabase", "port": 5432 } }
-
Add URLs and their check intervals in
config/urls_config.json
:{ "urls": [ { "url": "http://example.com", "regex": "Example Domain", "interval": "@every 1m" }, { "url": "http://another-example.com", "regex": "", "interval": "@every 5m" } ] }
- Run the application:
go run main.go
This project includes both unit tests and integration tests. To run the unit tests, use the following command:
go test ./... -short
websites_metrics/
├── config/
│ ├── config.go
│ ├── json_loader.go
│ ├── config_loader_interface.go
│ └── json
│ ├── db_config.json
│ └── urls_config.json
├── main.go
├── models/
│ └── metric.go
├── repository/
│ ├── postgres_metrics_repository.go
│ └── metrics_repository_interface.go
├── scheduler/
│ ├── cron_scheduler.go
│ └── scheduler_interface.go
└── metrics/
├── metrics_calculator_interface.go
└── url_metrics_calculator.go
- Located in
config/config_loader.go
- Implements
Load
method to load JSON configurations
- Located in
repository/
IMetricsRepository
interface defines theSave
methodMetricsRepository
struct implementsIMetricsRepository
- Located in
scheduler/
IScheduler
interface defines methods for scheduling tasksCronScheduler
struct implementsIScheduler
- Located in
metrics/
IMetricsCalculator
interface defines methods for metrics calculatingURLMetricsCalculator
struct implementsURLChecker