github.com/grpc-ecosystem/grpc-gateway/v2@v2.19.1/examples/internal/proto/examplepb/openapi_merge_b.pb.gw.go (about) 1 // Code generated by protoc-gen-grpc-gateway. DO NOT EDIT. 2 // source: examples/internal/proto/examplepb/openapi_merge_b.proto 3 4 /* 5 Package examplepb is a reverse proxy. 6 7 It translates gRPC into RESTful JSON APIs. 8 */ 9 package examplepb 10 11 import ( 12 "context" 13 "io" 14 "net/http" 15 16 "github.com/grpc-ecosystem/grpc-gateway/v2/runtime" 17 "github.com/grpc-ecosystem/grpc-gateway/v2/utilities" 18 "google.golang.org/grpc" 19 "google.golang.org/grpc/codes" 20 "google.golang.org/grpc/grpclog" 21 "google.golang.org/grpc/metadata" 22 "google.golang.org/grpc/status" 23 "google.golang.org/protobuf/proto" 24 ) 25 26 // Suppress "imported and not used" errors 27 var _ codes.Code 28 var _ io.Reader 29 var _ status.Status 30 var _ = runtime.String 31 var _ = utilities.NewDoubleArray 32 var _ = metadata.Join 33 34 func request_ServiceB_MethodOne_0(ctx context.Context, marshaler runtime.Marshaler, client ServiceBClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { 35 var protoReq InMessageB 36 var metadata runtime.ServerMetadata 37 38 if err := marshaler.NewDecoder(req.Body).Decode(&protoReq); err != nil && err != io.EOF { 39 return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) 40 } 41 42 msg, err := client.MethodOne(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) 43 return msg, metadata, err 44 45 } 46 47 func local_request_ServiceB_MethodOne_0(ctx context.Context, marshaler runtime.Marshaler, server ServiceBServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { 48 var protoReq InMessageB 49 var metadata runtime.ServerMetadata 50 51 if err := marshaler.NewDecoder(req.Body).Decode(&protoReq); err != nil && err != io.EOF { 52 return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) 53 } 54 55 msg, err := server.MethodOne(ctx, &protoReq) 56 return msg, metadata, err 57 58 } 59 60 func request_ServiceB_MethodTwo_0(ctx context.Context, marshaler runtime.Marshaler, client ServiceBClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { 61 var protoReq OutMessageB 62 var metadata runtime.ServerMetadata 63 64 if err := marshaler.NewDecoder(req.Body).Decode(&protoReq); err != nil && err != io.EOF { 65 return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) 66 } 67 68 msg, err := client.MethodTwo(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) 69 return msg, metadata, err 70 71 } 72 73 func local_request_ServiceB_MethodTwo_0(ctx context.Context, marshaler runtime.Marshaler, server ServiceBServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { 74 var protoReq OutMessageB 75 var metadata runtime.ServerMetadata 76 77 if err := marshaler.NewDecoder(req.Body).Decode(&protoReq); err != nil && err != io.EOF { 78 return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) 79 } 80 81 msg, err := server.MethodTwo(ctx, &protoReq) 82 return msg, metadata, err 83 84 } 85 86 // RegisterServiceBHandlerServer registers the http handlers for service ServiceB to "mux". 87 // UnaryRPC :call ServiceBServer directly. 88 // StreamingRPC :currently unsupported pending https://github.com/grpc/grpc-go/issues/906. 89 // Note that using this registration option will cause many gRPC library features to stop working. Consider using RegisterServiceBHandlerFromEndpoint instead. 90 func RegisterServiceBHandlerServer(ctx context.Context, mux *runtime.ServeMux, server ServiceBServer) error { 91 92 mux.Handle("POST", pattern_ServiceB_MethodOne_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { 93 ctx, cancel := context.WithCancel(req.Context()) 94 defer cancel() 95 var stream runtime.ServerTransportStream 96 ctx = grpc.NewContextWithServerTransportStream(ctx, &stream) 97 inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) 98 var err error 99 var annotatedContext context.Context 100 annotatedContext, err = runtime.AnnotateIncomingContext(ctx, mux, req, "/grpc.gateway.examples.internal.examplepb.ServiceB/MethodOne", runtime.WithHTTPPathPattern("/v1/example/b/1")) 101 if err != nil { 102 runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) 103 return 104 } 105 resp, md, err := local_request_ServiceB_MethodOne_0(annotatedContext, inboundMarshaler, server, req, pathParams) 106 md.HeaderMD, md.TrailerMD = metadata.Join(md.HeaderMD, stream.Header()), metadata.Join(md.TrailerMD, stream.Trailer()) 107 annotatedContext = runtime.NewServerMetadataContext(annotatedContext, md) 108 if err != nil { 109 runtime.HTTPError(annotatedContext, mux, outboundMarshaler, w, req, err) 110 return 111 } 112 113 forward_ServiceB_MethodOne_0(annotatedContext, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) 114 115 }) 116 117 mux.Handle("POST", pattern_ServiceB_MethodTwo_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { 118 ctx, cancel := context.WithCancel(req.Context()) 119 defer cancel() 120 var stream runtime.ServerTransportStream 121 ctx = grpc.NewContextWithServerTransportStream(ctx, &stream) 122 inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) 123 var err error 124 var annotatedContext context.Context 125 annotatedContext, err = runtime.AnnotateIncomingContext(ctx, mux, req, "/grpc.gateway.examples.internal.examplepb.ServiceB/MethodTwo", runtime.WithHTTPPathPattern("/v1/example/b/2")) 126 if err != nil { 127 runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) 128 return 129 } 130 resp, md, err := local_request_ServiceB_MethodTwo_0(annotatedContext, inboundMarshaler, server, req, pathParams) 131 md.HeaderMD, md.TrailerMD = metadata.Join(md.HeaderMD, stream.Header()), metadata.Join(md.TrailerMD, stream.Trailer()) 132 annotatedContext = runtime.NewServerMetadataContext(annotatedContext, md) 133 if err != nil { 134 runtime.HTTPError(annotatedContext, mux, outboundMarshaler, w, req, err) 135 return 136 } 137 138 forward_ServiceB_MethodTwo_0(annotatedContext, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) 139 140 }) 141 142 return nil 143 } 144 145 // RegisterServiceBHandlerFromEndpoint is same as RegisterServiceBHandler but 146 // automatically dials to "endpoint" and closes the connection when "ctx" gets done. 147 func RegisterServiceBHandlerFromEndpoint(ctx context.Context, mux *runtime.ServeMux, endpoint string, opts []grpc.DialOption) (err error) { 148 conn, err := grpc.DialContext(ctx, endpoint, opts...) 149 if err != nil { 150 return err 151 } 152 defer func() { 153 if err != nil { 154 if cerr := conn.Close(); cerr != nil { 155 grpclog.Infof("Failed to close conn to %s: %v", endpoint, cerr) 156 } 157 return 158 } 159 go func() { 160 <-ctx.Done() 161 if cerr := conn.Close(); cerr != nil { 162 grpclog.Infof("Failed to close conn to %s: %v", endpoint, cerr) 163 } 164 }() 165 }() 166 167 return RegisterServiceBHandler(ctx, mux, conn) 168 } 169 170 // RegisterServiceBHandler registers the http handlers for service ServiceB to "mux". 171 // The handlers forward requests to the grpc endpoint over "conn". 172 func RegisterServiceBHandler(ctx context.Context, mux *runtime.ServeMux, conn *grpc.ClientConn) error { 173 return RegisterServiceBHandlerClient(ctx, mux, NewServiceBClient(conn)) 174 } 175 176 // RegisterServiceBHandlerClient registers the http handlers for service ServiceB 177 // to "mux". The handlers forward requests to the grpc endpoint over the given implementation of "ServiceBClient". 178 // Note: the gRPC framework executes interceptors within the gRPC handler. If the passed in "ServiceBClient" 179 // doesn't go through the normal gRPC flow (creating a gRPC client etc.) then it will be up to the passed in 180 // "ServiceBClient" to call the correct interceptors. 181 func RegisterServiceBHandlerClient(ctx context.Context, mux *runtime.ServeMux, client ServiceBClient) error { 182 183 mux.Handle("POST", pattern_ServiceB_MethodOne_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { 184 ctx, cancel := context.WithCancel(req.Context()) 185 defer cancel() 186 inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) 187 var err error 188 var annotatedContext context.Context 189 annotatedContext, err = runtime.AnnotateContext(ctx, mux, req, "/grpc.gateway.examples.internal.examplepb.ServiceB/MethodOne", runtime.WithHTTPPathPattern("/v1/example/b/1")) 190 if err != nil { 191 runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) 192 return 193 } 194 resp, md, err := request_ServiceB_MethodOne_0(annotatedContext, inboundMarshaler, client, req, pathParams) 195 annotatedContext = runtime.NewServerMetadataContext(annotatedContext, md) 196 if err != nil { 197 runtime.HTTPError(annotatedContext, mux, outboundMarshaler, w, req, err) 198 return 199 } 200 201 forward_ServiceB_MethodOne_0(annotatedContext, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) 202 203 }) 204 205 mux.Handle("POST", pattern_ServiceB_MethodTwo_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { 206 ctx, cancel := context.WithCancel(req.Context()) 207 defer cancel() 208 inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) 209 var err error 210 var annotatedContext context.Context 211 annotatedContext, err = runtime.AnnotateContext(ctx, mux, req, "/grpc.gateway.examples.internal.examplepb.ServiceB/MethodTwo", runtime.WithHTTPPathPattern("/v1/example/b/2")) 212 if err != nil { 213 runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) 214 return 215 } 216 resp, md, err := request_ServiceB_MethodTwo_0(annotatedContext, inboundMarshaler, client, req, pathParams) 217 annotatedContext = runtime.NewServerMetadataContext(annotatedContext, md) 218 if err != nil { 219 runtime.HTTPError(annotatedContext, mux, outboundMarshaler, w, req, err) 220 return 221 } 222 223 forward_ServiceB_MethodTwo_0(annotatedContext, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) 224 225 }) 226 227 return nil 228 } 229 230 var ( 231 pattern_ServiceB_MethodOne_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 2, 3}, []string{"v1", "example", "b", "1"}, "")) 232 233 pattern_ServiceB_MethodTwo_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 2, 3}, []string{"v1", "example", "b", "2"}, "")) 234 ) 235 236 var ( 237 forward_ServiceB_MethodOne_0 = runtime.ForwardResponseMessage 238 239 forward_ServiceB_MethodTwo_0 = runtime.ForwardResponseMessage 240 )