From 6cfa51bd2f05042041fd9bc217abd9eec9da73d6 Mon Sep 17 00:00:00 2001 From: Artsiom Koltun Date: Mon, 5 Feb 2024 11:47:22 +0100 Subject: [PATCH] feat: run http bridge for storage Signed-off-by: Artsiom Koltun --- cmd/main.go | 28 +++++++++++++++++++++++----- 1 file changed, 23 insertions(+), 5 deletions(-) diff --git a/cmd/main.go b/cmd/main.go index 1ef92bbd..0eede7f1 100644 --- a/cmd/main.go +++ b/cmd/main.go @@ -154,10 +154,19 @@ func runGatewayServer(grpcPort int, httpPort int) { // Note: Make sure the gRPC server is running properly and accessible mux := runtime.NewServeMux() opts := []grpc.DialOption{grpc.WithTransportCredentials(insecure.NewCredentials())} - err := pc.RegisterInventoryServiceHandlerFromEndpoint(ctx, mux, fmt.Sprintf(":%d", grpcPort), opts) - if err != nil { - log.Panic("cannot register handler server") - } + endpoint := fmt.Sprintf("localhost:%d", grpcPort) + registerGatewayHandler(ctx, mux, endpoint, opts, pc.RegisterInventoryServiceHandlerFromEndpoint, "inventory") + + registerGatewayHandler(ctx, mux, endpoint, opts, pb.RegisterAioVolumeServiceHandlerFromEndpoint, "backend aio") + registerGatewayHandler(ctx, mux, endpoint, opts, pb.RegisterNullVolumeServiceHandlerFromEndpoint, "backend null") + registerGatewayHandler(ctx, mux, endpoint, opts, pb.RegisterNvmeRemoteControllerServiceHandlerFromEndpoint, "backend nvme") + + registerGatewayHandler(ctx, mux, endpoint, opts, pb.RegisterMiddleendEncryptionServiceHandlerFromEndpoint, "middleend encryption") + registerGatewayHandler(ctx, mux, endpoint, opts, pb.RegisterMiddleendQosVolumeServiceHandlerFromEndpoint, "middleend qos") + + registerGatewayHandler(ctx, mux, endpoint, opts, pb.RegisterFrontendVirtioBlkServiceHandlerFromEndpoint, "frontend virtio-blk") + registerGatewayHandler(ctx, mux, endpoint, opts, pb.RegisterFrontendVirtioScsiServiceHandlerFromEndpoint, "frontend virtio-scsi") + registerGatewayHandler(ctx, mux, endpoint, opts, pb.RegisterFrontendNvmeServiceHandlerFromEndpoint, "frontend nvme") // Start HTTP server (and proxy calls to gRPC server endpoint) log.Printf("HTTP Server listening at %v", httpPort) @@ -167,8 +176,17 @@ func runGatewayServer(grpcPort int, httpPort int) { ReadTimeout: 5 * time.Second, WriteTimeout: 10 * time.Second, } - err = server.ListenAndServe() + err := server.ListenAndServe() if err != nil { log.Panic("cannot start HTTP gateway server") } } + +type registerHandlerFunc func(context.Context, *runtime.ServeMux, string, []grpc.DialOption) error + +func registerGatewayHandler(ctx context.Context, mux *runtime.ServeMux, endpoint string, opts []grpc.DialOption, registerFunc registerHandlerFunc, serviceName string) { + err := registerFunc(ctx, mux, endpoint, opts) + if err != nil { + log.Panicf("cannot register %s handler server: %v", serviceName, err) + } +}