8b28a1ee01
modified: main_dc/yalarba/api_yal/internal/router/router.go add allhandlers.go file
40 lines
934 B
Go
40 lines
934 B
Go
package router
|
|
|
|
import (
|
|
"api_yal/internal/config"
|
|
"api_yal/internal/logger"
|
|
"api_yal/internal/handlers"
|
|
|
|
"encoding/json"
|
|
"github.com/go-chi/chi/v5"
|
|
"gorm.io/gorm"
|
|
"net/http"
|
|
)
|
|
|
|
func SetupRouter(db *gorm.DB, config *config.Config) http.Handler {
|
|
|
|
zapLogger := logger.Get()
|
|
zapLogger.Info("Start setup routers")
|
|
r := chi.NewRouter()
|
|
h := handlers.NewAllHandler()
|
|
|
|
// Health check
|
|
r.Get("/health", func(w http.ResponseWriter, r *http.Request) {
|
|
w.Header().Set("Content-Type", "application/json")
|
|
w.WriteHeader(http.StatusOK)
|
|
json.NewEncoder(w).Encode(map[string]string{"status": "healthy"})
|
|
})
|
|
|
|
r.Route("/auth", func(r chi.Router) {
|
|
r.Post("/register", h.AuthHandler().HandleAuth)
|
|
})
|
|
|
|
zapLogger.Info("End setup routers")
|
|
|
|
// Логируем все зарегистрированные маршруты
|
|
routeLogger := logger.NewRouteLogger(logger.NewWrapper(zapLogger))
|
|
routeLogger.LogRoutes(r)
|
|
|
|
return r
|
|
}
|