// RunRestServer : Will responsible to run the Rest server in different port.
RunRestServer : Will responsible to run the Rest server in different port.
// RunRestServer : Will responsible to run the Rest server in different port .
func RunRestServer(lc fx.Lifecycle, config *config.Config, conn *grpc.ClientConn) {
	Ctx, cancel := context.WithCancel(context.Background())
	defer cancel()
	mux := runtime.NewServeMux()
	if err := RegisterRESTModules(Ctx, mux, conn); err != nil {
		panic(err)
	}
	srv := &http.Server{
		Addr: config.Rest.Host + ":" + config.Rest.Port,
		Handler: http.TimeoutHandler(
			middleware.AddCors(middleware.AddRequestID(middleware.AddLogger(logger.Log, mux))),
			time.Second*time.Duration(config.Rest.RequestTimeout),
			"Context deadline exceeded",
		),
		WriteTimeout: time.Second * time.Duration(config.Rest.RequestTimeout),
	}
	logger.Log.Info("starting HTTP/REST gateway...")
	lc.Append(fx.Hook{
		OnStart: func(ctx context.Context) error {
			logger.Log.Info("starting HTTP/REST gateway...")
			go func() {
				_ = srv.ListenAndServe()
			}()
			return nil
		},
		OnStop: func(ctx context.Context) error {
			logger.Log.Info("Gracefully Shutting down REST server")
			_ = srv.Shutdown(Ctx)
			return nil
		},
	})
}
func RunRestServer ( lc fx . Lifecycle , config * config . Config , conn * grpc . ClientConn ) { Ctx , cancel := context . WithCancel ( context . Background ( ) ) defer cancel ( ) mux := runtime . NewServeMux ( ) if err := RegisterRESTModules ( Ctx , mux , conn ) ; err != nil { panic ( err ) } srv := & http . Server { Addr : config . Rest . Host + " " + config . Rest . Port , Handler : http . TimeoutHandler ( middleware . AddCors ( middleware . AddRequestID ( middleware . AddLogger ( logger . Log , mux ) ) ) , time . Second * time . Duration ( config . Rest . RequestTimeout ) , " " , ) , WriteTimeout : time . Second * time . Duration ( config . Rest . RequestTimeout ) , } logger . Log . Info ( " " ) lc . Append ( fx . Hook { OnStart : func ( ctx context . Context ) error { logger . Log . Info ( " " ) go func ( ) { _ = srv . ListenAndServe ( ) } ( ) return nil } , OnStop : func ( ctx context . Context ) error { logger . Log . Info ( " " ) _ = srv . Shutdown ( Ctx ) return nil } , } ) }
RunRestServer : Will responsible to run the Rest server in different port.
RunRestServer : Will responsible to run the Rest server in different port .
// add handler with middleware //Read Timeout is the time required to read the request body. // To mitigate the impact of deadlocks in application startup and // shutdown, Fx imposes a time limit on OnStart and OnStop hooks. By // default, hooks have a total of 15 seconds to complete. Timeouts are // passed via Go's usual context.Context. // In production, we'd want to separate the Listen and Serve phases for // better error-handling. // run HTTP gateway