modified: serv_nginx/nginx/nginx-ssl.conf
modified: yalarba/serv_golang_rest_api/internal/server/server.go add healcheck points into rest api server on golang for yalarba.ru
This commit is contained in:
@@ -43,7 +43,7 @@ server {
|
||||
|
||||
# New location for REST API
|
||||
location /api/ {
|
||||
proxy_pass http://localhost:8888/;
|
||||
proxy_pass http://0.0.0.0:8888/;
|
||||
proxy_set_header Host $host;
|
||||
proxy_set_header X-Real-IP $remote_addr;
|
||||
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
||||
|
||||
@@ -37,6 +37,7 @@ func (s *Server) configureRouter(db *gorm.DB) {
|
||||
|
||||
// API routes
|
||||
s.router.Route("/v1", func(r chi.Router) {
|
||||
s.router.Get("/check", s.healthCheck)
|
||||
s.setupUserRoutes(r, db)
|
||||
})
|
||||
}
|
||||
@@ -45,14 +46,15 @@ func (s *Server) setupUserRoutes(r chi.Router, db *gorm.DB) {
|
||||
userRepo := repository.NewUserRepository(s.db)
|
||||
userService := service.NewUserService(userRepo)
|
||||
userHandler := handlers.NewUserHandler(userService)
|
||||
|
||||
authHandler := &handlers.AuthHandler{DB: db}
|
||||
oauthHandler := &handlers.OAuthHandler{DB: db}
|
||||
|
||||
authHandler := &handlers.AuthHandler{DB: db}
|
||||
oauthHandler := &handlers.OAuthHandler{DB: db}
|
||||
|
||||
// Публичные маршруты
|
||||
r.Route("/auth", func(r chi.Router) {
|
||||
r.Post("/register", authHandler.Register)
|
||||
r.Post("/login", authHandler.Login)
|
||||
r.Get("check", s.healthCheck)
|
||||
|
||||
// OAuth routes
|
||||
r.Get("/google", oauthHandler.GoogleLogin)
|
||||
@@ -71,6 +73,7 @@ func (s *Server) setupUserRoutes(r chi.Router, db *gorm.DB) {
|
||||
r.Get("/", userHandler.GetAllUsers)
|
||||
r.Post("/", userHandler.CreateUser)
|
||||
r.Get("/{id}", userHandler.GetUser)
|
||||
r.Get("check", s.healthCheck)
|
||||
})
|
||||
|
||||
})
|
||||
@@ -83,7 +86,7 @@ func (s *Server) healthCheck(w http.ResponseWriter, r *http.Request) {
|
||||
http.Error(w, "Database connection error", http.StatusServiceUnavailable)
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
if err := sqlDB.Ping(); err != nil {
|
||||
http.Error(w, "Database ping failed", http.StatusServiceUnavailable)
|
||||
return
|
||||
|
||||
Reference in New Issue
Block a user