Files
tp/serv_nginx/api_bb/internal/routes/routes.go
T
valitovgaziz 7ec95ab722 modified: internal/routes/routes.go
add to v1/check the check function
2025-10-08 04:26:16 +05:00

52 lines
1.1 KiB
Go

package routes
import (
"net/http"
"github.com/go-chi/chi/v5"
"gorm.io/gorm"
"go-rest-api/internal/handlers"
"go-rest-api/internal/repository"
"go-rest-api/internal/service"
"go-rest-api/pkg/middleware"
)
func SetupRouter(db *gorm.DB) http.Handler {
r := chi.NewRouter()
// Apply common middleware
for _, m := range middleware.CommonMiddleware() {
r.Use(m)
}
// Initialize repositories
userRepo := repository.NewUserRepository(db)
// Initialize services
authService := service.NewAuthService(userRepo)
// Initialize handlers
healthHandler := handlers.NewHealthHandler()
authHandler := handlers.NewAuthHandler(authService)
h := handlers.NewHealthHandler()
// Health routes
r.Mount("/", healthHandler.Routes())
// API v1 routes
r.Route("/v1", func(r chi.Router) {
// Add the new /check route
r.Get("/check", h.Check)
r.Mount("/auth", authHandler.Routes())
// Здесь будут добавлены другие маршруты:
// r.Mount("/users", userHandler.Routes())
// r.Mount("/events", eventHandler.Routes())
// r.Mount("/reviews", reviewHandler.Routes())
})
return r
}