remove http server from auth
This commit is contained in:
@@ -1,7 +1,6 @@
|
|||||||
package server
|
package server
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
"log"
|
||||||
"net"
|
"net"
|
||||||
@@ -10,7 +9,6 @@ import (
|
|||||||
|
|
||||||
"datarush/internal/auth/config"
|
"datarush/internal/auth/config"
|
||||||
grpcHandlers "datarush/internal/auth/handler/grpc"
|
grpcHandlers "datarush/internal/auth/handler/grpc"
|
||||||
httpHandlers "datarush/internal/auth/handler/http"
|
|
||||||
authPostgresRepo "datarush/internal/auth/repository/postgres"
|
authPostgresRepo "datarush/internal/auth/repository/postgres"
|
||||||
"datarush/internal/auth/service"
|
"datarush/internal/auth/service"
|
||||||
|
|
||||||
@@ -64,10 +62,6 @@ func (s *Server) Start() error {
|
|||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
|
|
||||||
if err := s.startHTTPServer(); err != nil {
|
|
||||||
return fmt.Errorf("failed to start HTTP server: %w", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -88,60 +82,9 @@ func (s *Server) registerGRPCServices() error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Server) startHTTPServer() error {
|
|
||||||
userRepo := authPostgresRepo.NewUserRepository(s.db)
|
|
||||||
|
|
||||||
authService := service.NewAuthService(userRepo, s.config.JWTSecret)
|
|
||||||
|
|
||||||
authHandler := httpHandlers.NewAuthHandler(authService)
|
|
||||||
|
|
||||||
mux := http.NewServeMux()
|
|
||||||
|
|
||||||
mux.HandleFunc("/api/v1/sign-up", func(w http.ResponseWriter, r *http.Request) {
|
|
||||||
if r.Method != http.MethodPost {
|
|
||||||
http.Error(w, "Method not allowed", http.StatusMethodNotAllowed)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
authHandler.SignUp(w, r)
|
|
||||||
})
|
|
||||||
|
|
||||||
mux.HandleFunc("/api/v1/sign-in", func(w http.ResponseWriter, r *http.Request) {
|
|
||||||
if r.Method != http.MethodPost {
|
|
||||||
http.Error(w, "Method not allowed", http.StatusMethodNotAllowed)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
authHandler.SignIn(w, r)
|
|
||||||
})
|
|
||||||
|
|
||||||
s.httpServer = &http.Server{
|
|
||||||
Addr: fmt.Sprintf(":%d", s.config.HTTPPort),
|
|
||||||
Handler: mux,
|
|
||||||
ReadTimeout: httpReadTimeout,
|
|
||||||
WriteTimeout: httpWriteTimeout,
|
|
||||||
IdleTimeout: httpIdleTimeout,
|
|
||||||
}
|
|
||||||
|
|
||||||
go func() {
|
|
||||||
log.Printf("starting HTTP server on port %d", s.config.HTTPPort)
|
|
||||||
if err := s.httpServer.ListenAndServe(); err != nil && err != http.ErrServerClosed {
|
|
||||||
log.Fatalf("failed to start HTTP server: %v", err)
|
|
||||||
}
|
|
||||||
}()
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *Server) Stop() {
|
func (s *Server) Stop() {
|
||||||
log.Println("shutting down auth server...")
|
log.Println("shutting down auth server...")
|
||||||
|
|
||||||
if s.httpServer != nil {
|
|
||||||
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
|
|
||||||
defer cancel()
|
|
||||||
if err := s.httpServer.Shutdown(ctx); err != nil {
|
|
||||||
log.Printf("failed to shutdown HTTP server: %v", err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if s.grpcServer != nil {
|
if s.grpcServer != nil {
|
||||||
s.grpcServer.GracefulStop()
|
s.grpcServer.GracefulStop()
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user