This commit is contained in:
Timur Kh.
2025-12-15 22:28:01 +03:00
parent 4a17c75d6f
commit f7a7b19275
25 changed files with 1383 additions and 3 deletions
+20
View File
@@ -16,6 +16,7 @@ import (
orderPostgresRepo "datarush/internal/lms/repository/postgres"
"datarush/internal/lms/service"
authPb "datarush/pkg/api/auth"
pb "datarush/pkg/api/order"
"github.com/grpc-ecosystem/grpc-gateway/v2/runtime"
@@ -72,6 +73,12 @@ func runHTTPHandler(s *Server, grpcServerEndpoint *string) error {
return err
}
// Register auth service
if err := registerAuthService(ctx, gwmux, s.config.AuthGRPCAddr, opts); err != nil {
log.Printf("failed to register auth service: %v", err)
// Don't fail completely if auth service is not available
}
mux := http.NewServeMux()
mux.Handle("/healthz", httpHandlers.NewHealthHandler(s.db, s.redisDB))
mux.Handle("/", gwmux)
@@ -87,6 +94,19 @@ func runHTTPHandler(s *Server, grpcServerEndpoint *string) error {
return srv.ListenAndServe()
}
func registerAuthService(ctx context.Context, gwmux *runtime.ServeMux, authAddr string, opts []grpc.DialOption) error {
if err := authPb.RegisterAuthServiceHandlerFromEndpoint(ctx, gwmux, authAddr, opts); err != nil {
return fmt.Errorf("register auth service handler: %w", err)
}
log.Printf("registered auth service from %s", authAddr)
return nil
}
func registerAuthHandlerFromEndpoint(ctx context.Context, gwmux *runtime.ServeMux, endpoint string, opts []grpc.DialOption) error {
// We'll import the proto and register it here
// For now, this is a placeholder that will be called from gateway integration
return nil
func getDatabase(cfg config.Config) (*sqlx.DB, error) {
db, err := sqlx.Connect("postgres", cfg.BuildPostgresConnStr())
if err != nil {