feat(servers): implement saervers monitoring

This commit is contained in:
2025-06-17 12:50:50 +03:00
parent 0e2e02622d
commit 42f2b68848
7 changed files with 217 additions and 5 deletions

View File

@@ -1,6 +1,7 @@
package main
import (
"context"
"log"
"net/http"
"os"
@@ -18,8 +19,12 @@ func main() {
db := database.Connect()
defer db.Close()
// --- Собираем наши зависимости (Dependency Injection) ---
userRepo := &database.UserRepository{DB: db}
serverRepo := &database.ServerRepository{DB: db}
serverPoller := &core.ServerPoller{Repo: serverRepo}
// Запускаем поллер в фоновой горутине
go serverPoller.Start(context.Background())
// Сервисы
userService := &core.UserService{Repo: userRepo}
@@ -39,9 +44,9 @@ func main() {
}
// Хендлеры
userHandler := &api.UserHandler{Service: userService}
authHandler := &api.AuthHandler{Service: authService} // Новый хендлер
profileHandler := &api.ProfileHandler{Service: profileService} // Новый хендлер
authHandler := &api.AuthHandler{Service: authService}
profileHandler := &api.ProfileHandler{Service: profileService}
serverHandler := &api.ServerHandler{Repo: serverRepo}
// --- Настраиваем роутер ---
r := chi.NewRouter()
r.Use(middleware.Logger)
@@ -51,7 +56,7 @@ func main() {
r.Route("/api", func(r chi.Router) {
r.Post("/register", userHandler.Register)
r.Post("/login", authHandler.Login)
// Здесь будет публичный эндпоинт для логина в веб-интерфейс
r.Get("/servers", serverHandler.GetServers)
})
r.Route("/authserver", func(r chi.Router) {
r.Post("/authenticate", authHandler.Authenticate)