github.com/grpc-ecosystem/grpc-gateway/v2@v2.19.1/examples/internal/proto/examplepb/openapi_merge_a.pb.gw.go (about) 1 // Code generated by protoc-gen-grpc-gateway. DO NOT EDIT. 2 // source: examples/internal/proto/examplepb/openapi_merge_a.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_ServiceA_MethodOne_0(ctx context.Context, marshaler runtime.Marshaler, client ServiceAClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { 35 var protoReq InMessageA 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_ServiceA_MethodOne_0(ctx context.Context, marshaler runtime.Marshaler, server ServiceAServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { 48 var protoReq InMessageA 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_ServiceA_MethodTwo_0(ctx context.Context, marshaler runtime.Marshaler, client ServiceAClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { 61 var protoReq OutMessageA 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_ServiceA_MethodTwo_0(ctx context.Context, marshaler runtime.Marshaler, server ServiceAServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { 74 var protoReq OutMessageA 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 func request_ServiceC_MethodOne_0(ctx context.Context, marshaler runtime.Marshaler, client ServiceCClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { 87 var protoReq InMessageA 88 var metadata runtime.ServerMetadata 89 90 if err := marshaler.NewDecoder(req.Body).Decode(&protoReq); err != nil && err != io.EOF { 91 return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) 92 } 93 94 msg, err := client.MethodOne(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) 95 return msg, metadata, err 96 97 } 98 99 func local_request_ServiceC_MethodOne_0(ctx context.Context, marshaler runtime.Marshaler, server ServiceCServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { 100 var protoReq InMessageA 101 var metadata runtime.ServerMetadata 102 103 if err := marshaler.NewDecoder(req.Body).Decode(&protoReq); err != nil && err != io.EOF { 104 return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) 105 } 106 107 msg, err := server.MethodOne(ctx, &protoReq) 108 return msg, metadata, err 109 110 } 111 112 func request_ServiceC_MethodTwo_0(ctx context.Context, marshaler runtime.Marshaler, client ServiceCClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { 113 var protoReq OutMessageA 114 var metadata runtime.ServerMetadata 115 116 if err := marshaler.NewDecoder(req.Body).Decode(&protoReq); err != nil && err != io.EOF { 117 return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) 118 } 119 120 msg, err := client.MethodTwo(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) 121 return msg, metadata, err 122 123 } 124 125 func local_request_ServiceC_MethodTwo_0(ctx context.Context, marshaler runtime.Marshaler, server ServiceCServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { 126 var protoReq OutMessageA 127 var metadata runtime.ServerMetadata 128 129 if err := marshaler.NewDecoder(req.Body).Decode(&protoReq); err != nil && err != io.EOF { 130 return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) 131 } 132 133 msg, err := server.MethodTwo(ctx, &protoReq) 134 return msg, metadata, err 135 136 } 137 138 // RegisterServiceAHandlerServer registers the http handlers for service ServiceA to "mux". 139 // UnaryRPC :call ServiceAServer directly. 140 // StreamingRPC :currently unsupported pending https://github.com/grpc/grpc-go/issues/906. 141 // Note that using this registration option will cause many gRPC library features to stop working. Consider using RegisterServiceAHandlerFromEndpoint instead. 142 func RegisterServiceAHandlerServer(ctx context.Context, mux *runtime.ServeMux, server ServiceAServer) error { 143 144 mux.Handle("POST", pattern_ServiceA_MethodOne_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { 145 ctx, cancel := context.WithCancel(req.Context()) 146 defer cancel() 147 var stream runtime.ServerTransportStream 148 ctx = grpc.NewContextWithServerTransportStream(ctx, &stream) 149 inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) 150 var err error 151 var annotatedContext context.Context 152 annotatedContext, err = runtime.AnnotateIncomingContext(ctx, mux, req, "/grpc.gateway.examples.internal.examplepb.ServiceA/MethodOne", runtime.WithHTTPPathPattern("/v1/example/a/1")) 153 if err != nil { 154 runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) 155 return 156 } 157 resp, md, err := local_request_ServiceA_MethodOne_0(annotatedContext, inboundMarshaler, server, req, pathParams) 158 md.HeaderMD, md.TrailerMD = metadata.Join(md.HeaderMD, stream.Header()), metadata.Join(md.TrailerMD, stream.Trailer()) 159 annotatedContext = runtime.NewServerMetadataContext(annotatedContext, md) 160 if err != nil { 161 runtime.HTTPError(annotatedContext, mux, outboundMarshaler, w, req, err) 162 return 163 } 164 165 forward_ServiceA_MethodOne_0(annotatedContext, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) 166 167 }) 168 169 mux.Handle("POST", pattern_ServiceA_MethodTwo_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { 170 ctx, cancel := context.WithCancel(req.Context()) 171 defer cancel() 172 var stream runtime.ServerTransportStream 173 ctx = grpc.NewContextWithServerTransportStream(ctx, &stream) 174 inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) 175 var err error 176 var annotatedContext context.Context 177 annotatedContext, err = runtime.AnnotateIncomingContext(ctx, mux, req, "/grpc.gateway.examples.internal.examplepb.ServiceA/MethodTwo", runtime.WithHTTPPathPattern("/v1/example/a/2")) 178 if err != nil { 179 runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) 180 return 181 } 182 resp, md, err := local_request_ServiceA_MethodTwo_0(annotatedContext, inboundMarshaler, server, req, pathParams) 183 md.HeaderMD, md.TrailerMD = metadata.Join(md.HeaderMD, stream.Header()), metadata.Join(md.TrailerMD, stream.Trailer()) 184 annotatedContext = runtime.NewServerMetadataContext(annotatedContext, md) 185 if err != nil { 186 runtime.HTTPError(annotatedContext, mux, outboundMarshaler, w, req, err) 187 return 188 } 189 190 forward_ServiceA_MethodTwo_0(annotatedContext, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) 191 192 }) 193 194 return nil 195 } 196 197 // RegisterServiceCHandlerServer registers the http handlers for service ServiceC to "mux". 198 // UnaryRPC :call ServiceCServer directly. 199 // StreamingRPC :currently unsupported pending https://github.com/grpc/grpc-go/issues/906. 200 // Note that using this registration option will cause many gRPC library features to stop working. Consider using RegisterServiceCHandlerFromEndpoint instead. 201 func RegisterServiceCHandlerServer(ctx context.Context, mux *runtime.ServeMux, server ServiceCServer) error { 202 203 mux.Handle("POST", pattern_ServiceC_MethodOne_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { 204 ctx, cancel := context.WithCancel(req.Context()) 205 defer cancel() 206 var stream runtime.ServerTransportStream 207 ctx = grpc.NewContextWithServerTransportStream(ctx, &stream) 208 inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) 209 var err error 210 var annotatedContext context.Context 211 annotatedContext, err = runtime.AnnotateIncomingContext(ctx, mux, req, "/grpc.gateway.examples.internal.examplepb.ServiceC/MethodOne", runtime.WithHTTPPathPattern("/v1/example/c/1")) 212 if err != nil { 213 runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) 214 return 215 } 216 resp, md, err := local_request_ServiceC_MethodOne_0(annotatedContext, inboundMarshaler, server, req, pathParams) 217 md.HeaderMD, md.TrailerMD = metadata.Join(md.HeaderMD, stream.Header()), metadata.Join(md.TrailerMD, stream.Trailer()) 218 annotatedContext = runtime.NewServerMetadataContext(annotatedContext, md) 219 if err != nil { 220 runtime.HTTPError(annotatedContext, mux, outboundMarshaler, w, req, err) 221 return 222 } 223 224 forward_ServiceC_MethodOne_0(annotatedContext, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) 225 226 }) 227 228 mux.Handle("POST", pattern_ServiceC_MethodTwo_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { 229 ctx, cancel := context.WithCancel(req.Context()) 230 defer cancel() 231 var stream runtime.ServerTransportStream 232 ctx = grpc.NewContextWithServerTransportStream(ctx, &stream) 233 inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) 234 var err error 235 var annotatedContext context.Context 236 annotatedContext, err = runtime.AnnotateIncomingContext(ctx, mux, req, "/grpc.gateway.examples.internal.examplepb.ServiceC/MethodTwo", runtime.WithHTTPPathPattern("/v1/example/c/2")) 237 if err != nil { 238 runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) 239 return 240 } 241 resp, md, err := local_request_ServiceC_MethodTwo_0(annotatedContext, inboundMarshaler, server, req, pathParams) 242 md.HeaderMD, md.TrailerMD = metadata.Join(md.HeaderMD, stream.Header()), metadata.Join(md.TrailerMD, stream.Trailer()) 243 annotatedContext = runtime.NewServerMetadataContext(annotatedContext, md) 244 if err != nil { 245 runtime.HTTPError(annotatedContext, mux, outboundMarshaler, w, req, err) 246 return 247 } 248 249 forward_ServiceC_MethodTwo_0(annotatedContext, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) 250 251 }) 252 253 return nil 254 } 255 256 // RegisterServiceAHandlerFromEndpoint is same as RegisterServiceAHandler but 257 // automatically dials to "endpoint" and closes the connection when "ctx" gets done. 258 func RegisterServiceAHandlerFromEndpoint(ctx context.Context, mux *runtime.ServeMux, endpoint string, opts []grpc.DialOption) (err error) { 259 conn, err := grpc.DialContext(ctx, endpoint, opts...) 260 if err != nil { 261 return err 262 } 263 defer func() { 264 if err != nil { 265 if cerr := conn.Close(); cerr != nil { 266 grpclog.Infof("Failed to close conn to %s: %v", endpoint, cerr) 267 } 268 return 269 } 270 go func() { 271 <-ctx.Done() 272 if cerr := conn.Close(); cerr != nil { 273 grpclog.Infof("Failed to close conn to %s: %v", endpoint, cerr) 274 } 275 }() 276 }() 277 278 return RegisterServiceAHandler(ctx, mux, conn) 279 } 280 281 // RegisterServiceAHandler registers the http handlers for service ServiceA to "mux". 282 // The handlers forward requests to the grpc endpoint over "conn". 283 func RegisterServiceAHandler(ctx context.Context, mux *runtime.ServeMux, conn *grpc.ClientConn) error { 284 return RegisterServiceAHandlerClient(ctx, mux, NewServiceAClient(conn)) 285 } 286 287 // RegisterServiceAHandlerClient registers the http handlers for service ServiceA 288 // to "mux". The handlers forward requests to the grpc endpoint over the given implementation of "ServiceAClient". 289 // Note: the gRPC framework executes interceptors within the gRPC handler. If the passed in "ServiceAClient" 290 // doesn't go through the normal gRPC flow (creating a gRPC client etc.) then it will be up to the passed in 291 // "ServiceAClient" to call the correct interceptors. 292 func RegisterServiceAHandlerClient(ctx context.Context, mux *runtime.ServeMux, client ServiceAClient) error { 293 294 mux.Handle("POST", pattern_ServiceA_MethodOne_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { 295 ctx, cancel := context.WithCancel(req.Context()) 296 defer cancel() 297 inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) 298 var err error 299 var annotatedContext context.Context 300 annotatedContext, err = runtime.AnnotateContext(ctx, mux, req, "/grpc.gateway.examples.internal.examplepb.ServiceA/MethodOne", runtime.WithHTTPPathPattern("/v1/example/a/1")) 301 if err != nil { 302 runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) 303 return 304 } 305 resp, md, err := request_ServiceA_MethodOne_0(annotatedContext, inboundMarshaler, client, req, pathParams) 306 annotatedContext = runtime.NewServerMetadataContext(annotatedContext, md) 307 if err != nil { 308 runtime.HTTPError(annotatedContext, mux, outboundMarshaler, w, req, err) 309 return 310 } 311 312 forward_ServiceA_MethodOne_0(annotatedContext, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) 313 314 }) 315 316 mux.Handle("POST", pattern_ServiceA_MethodTwo_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { 317 ctx, cancel := context.WithCancel(req.Context()) 318 defer cancel() 319 inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) 320 var err error 321 var annotatedContext context.Context 322 annotatedContext, err = runtime.AnnotateContext(ctx, mux, req, "/grpc.gateway.examples.internal.examplepb.ServiceA/MethodTwo", runtime.WithHTTPPathPattern("/v1/example/a/2")) 323 if err != nil { 324 runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) 325 return 326 } 327 resp, md, err := request_ServiceA_MethodTwo_0(annotatedContext, inboundMarshaler, client, req, pathParams) 328 annotatedContext = runtime.NewServerMetadataContext(annotatedContext, md) 329 if err != nil { 330 runtime.HTTPError(annotatedContext, mux, outboundMarshaler, w, req, err) 331 return 332 } 333 334 forward_ServiceA_MethodTwo_0(annotatedContext, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) 335 336 }) 337 338 return nil 339 } 340 341 var ( 342 pattern_ServiceA_MethodOne_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 2, 3}, []string{"v1", "example", "a", "1"}, "")) 343 344 pattern_ServiceA_MethodTwo_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 2, 3}, []string{"v1", "example", "a", "2"}, "")) 345 ) 346 347 var ( 348 forward_ServiceA_MethodOne_0 = runtime.ForwardResponseMessage 349 350 forward_ServiceA_MethodTwo_0 = runtime.ForwardResponseMessage 351 ) 352 353 // RegisterServiceCHandlerFromEndpoint is same as RegisterServiceCHandler but 354 // automatically dials to "endpoint" and closes the connection when "ctx" gets done. 355 func RegisterServiceCHandlerFromEndpoint(ctx context.Context, mux *runtime.ServeMux, endpoint string, opts []grpc.DialOption) (err error) { 356 conn, err := grpc.DialContext(ctx, endpoint, opts...) 357 if err != nil { 358 return err 359 } 360 defer func() { 361 if err != nil { 362 if cerr := conn.Close(); cerr != nil { 363 grpclog.Infof("Failed to close conn to %s: %v", endpoint, cerr) 364 } 365 return 366 } 367 go func() { 368 <-ctx.Done() 369 if cerr := conn.Close(); cerr != nil { 370 grpclog.Infof("Failed to close conn to %s: %v", endpoint, cerr) 371 } 372 }() 373 }() 374 375 return RegisterServiceCHandler(ctx, mux, conn) 376 } 377 378 // RegisterServiceCHandler registers the http handlers for service ServiceC to "mux". 379 // The handlers forward requests to the grpc endpoint over "conn". 380 func RegisterServiceCHandler(ctx context.Context, mux *runtime.ServeMux, conn *grpc.ClientConn) error { 381 return RegisterServiceCHandlerClient(ctx, mux, NewServiceCClient(conn)) 382 } 383 384 // RegisterServiceCHandlerClient registers the http handlers for service ServiceC 385 // to "mux". The handlers forward requests to the grpc endpoint over the given implementation of "ServiceCClient". 386 // Note: the gRPC framework executes interceptors within the gRPC handler. If the passed in "ServiceCClient" 387 // doesn't go through the normal gRPC flow (creating a gRPC client etc.) then it will be up to the passed in 388 // "ServiceCClient" to call the correct interceptors. 389 func RegisterServiceCHandlerClient(ctx context.Context, mux *runtime.ServeMux, client ServiceCClient) error { 390 391 mux.Handle("POST", pattern_ServiceC_MethodOne_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { 392 ctx, cancel := context.WithCancel(req.Context()) 393 defer cancel() 394 inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) 395 var err error 396 var annotatedContext context.Context 397 annotatedContext, err = runtime.AnnotateContext(ctx, mux, req, "/grpc.gateway.examples.internal.examplepb.ServiceC/MethodOne", runtime.WithHTTPPathPattern("/v1/example/c/1")) 398 if err != nil { 399 runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) 400 return 401 } 402 resp, md, err := request_ServiceC_MethodOne_0(annotatedContext, inboundMarshaler, client, req, pathParams) 403 annotatedContext = runtime.NewServerMetadataContext(annotatedContext, md) 404 if err != nil { 405 runtime.HTTPError(annotatedContext, mux, outboundMarshaler, w, req, err) 406 return 407 } 408 409 forward_ServiceC_MethodOne_0(annotatedContext, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) 410 411 }) 412 413 mux.Handle("POST", pattern_ServiceC_MethodTwo_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { 414 ctx, cancel := context.WithCancel(req.Context()) 415 defer cancel() 416 inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) 417 var err error 418 var annotatedContext context.Context 419 annotatedContext, err = runtime.AnnotateContext(ctx, mux, req, "/grpc.gateway.examples.internal.examplepb.ServiceC/MethodTwo", runtime.WithHTTPPathPattern("/v1/example/c/2")) 420 if err != nil { 421 runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) 422 return 423 } 424 resp, md, err := request_ServiceC_MethodTwo_0(annotatedContext, inboundMarshaler, client, req, pathParams) 425 annotatedContext = runtime.NewServerMetadataContext(annotatedContext, md) 426 if err != nil { 427 runtime.HTTPError(annotatedContext, mux, outboundMarshaler, w, req, err) 428 return 429 } 430 431 forward_ServiceC_MethodTwo_0(annotatedContext, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) 432 433 }) 434 435 return nil 436 } 437 438 var ( 439 pattern_ServiceC_MethodOne_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 2, 3}, []string{"v1", "example", "c", "1"}, "")) 440 441 pattern_ServiceC_MethodTwo_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 2, 3}, []string{"v1", "example", "c", "2"}, "")) 442 ) 443 444 var ( 445 forward_ServiceC_MethodOne_0 = runtime.ForwardResponseMessage 446 447 forward_ServiceC_MethodTwo_0 = runtime.ForwardResponseMessage 448 )