...

Source file src/github.com/grpc-ecosystem/grpc-gateway/v2/examples/internal/proto/examplepb/ignore_comment.pb.gw.go

Documentation: github.com/grpc-ecosystem/grpc-gateway/v2/examples/internal/proto/examplepb

     1  // Code generated by protoc-gen-grpc-gateway. DO NOT EDIT.
     2  // source: examples/internal/proto/examplepb/ignore_comment.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_FooService_Foo_0(ctx context.Context, marshaler runtime.Marshaler, client FooServiceClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) {
    35  	var protoReq FooRequest
    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.Foo(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD))
    43  	return msg, metadata, err
    44  
    45  }
    46  
    47  func local_request_FooService_Foo_0(ctx context.Context, marshaler runtime.Marshaler, server FooServiceServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) {
    48  	var protoReq FooRequest
    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.Foo(ctx, &protoReq)
    56  	return msg, metadata, err
    57  
    58  }
    59  
    60  // RegisterFooServiceHandlerServer registers the http handlers for service FooService to "mux".
    61  // UnaryRPC     :call FooServiceServer directly.
    62  // StreamingRPC :currently unsupported pending https://github.com/grpc/grpc-go/issues/906.
    63  // Note that using this registration option will cause many gRPC library features to stop working. Consider using RegisterFooServiceHandlerFromEndpoint instead.
    64  func RegisterFooServiceHandlerServer(ctx context.Context, mux *runtime.ServeMux, server FooServiceServer) error {
    65  
    66  	mux.Handle("POST", pattern_FooService_Foo_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) {
    67  		ctx, cancel := context.WithCancel(req.Context())
    68  		defer cancel()
    69  		var stream runtime.ServerTransportStream
    70  		ctx = grpc.NewContextWithServerTransportStream(ctx, &stream)
    71  		inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req)
    72  		var err error
    73  		var annotatedContext context.Context
    74  		annotatedContext, err = runtime.AnnotateIncomingContext(ctx, mux, req, "/grpc.gateway.examples.internal.proto.examplepb.FooService/Foo", runtime.WithHTTPPathPattern("/v1/example/foo"))
    75  		if err != nil {
    76  			runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err)
    77  			return
    78  		}
    79  		resp, md, err := local_request_FooService_Foo_0(annotatedContext, inboundMarshaler, server, req, pathParams)
    80  		md.HeaderMD, md.TrailerMD = metadata.Join(md.HeaderMD, stream.Header()), metadata.Join(md.TrailerMD, stream.Trailer())
    81  		annotatedContext = runtime.NewServerMetadataContext(annotatedContext, md)
    82  		if err != nil {
    83  			runtime.HTTPError(annotatedContext, mux, outboundMarshaler, w, req, err)
    84  			return
    85  		}
    86  
    87  		forward_FooService_Foo_0(annotatedContext, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...)
    88  
    89  	})
    90  
    91  	return nil
    92  }
    93  
    94  // RegisterFooServiceHandlerFromEndpoint is same as RegisterFooServiceHandler but
    95  // automatically dials to "endpoint" and closes the connection when "ctx" gets done.
    96  func RegisterFooServiceHandlerFromEndpoint(ctx context.Context, mux *runtime.ServeMux, endpoint string, opts []grpc.DialOption) (err error) {
    97  	conn, err := grpc.DialContext(ctx, endpoint, opts...)
    98  	if err != nil {
    99  		return err
   100  	}
   101  	defer func() {
   102  		if err != nil {
   103  			if cerr := conn.Close(); cerr != nil {
   104  				grpclog.Infof("Failed to close conn to %s: %v", endpoint, cerr)
   105  			}
   106  			return
   107  		}
   108  		go func() {
   109  			<-ctx.Done()
   110  			if cerr := conn.Close(); cerr != nil {
   111  				grpclog.Infof("Failed to close conn to %s: %v", endpoint, cerr)
   112  			}
   113  		}()
   114  	}()
   115  
   116  	return RegisterFooServiceHandler(ctx, mux, conn)
   117  }
   118  
   119  // RegisterFooServiceHandler registers the http handlers for service FooService to "mux".
   120  // The handlers forward requests to the grpc endpoint over "conn".
   121  func RegisterFooServiceHandler(ctx context.Context, mux *runtime.ServeMux, conn *grpc.ClientConn) error {
   122  	return RegisterFooServiceHandlerClient(ctx, mux, NewFooServiceClient(conn))
   123  }
   124  
   125  // RegisterFooServiceHandlerClient registers the http handlers for service FooService
   126  // to "mux". The handlers forward requests to the grpc endpoint over the given implementation of "FooServiceClient".
   127  // Note: the gRPC framework executes interceptors within the gRPC handler. If the passed in "FooServiceClient"
   128  // doesn't go through the normal gRPC flow (creating a gRPC client etc.) then it will be up to the passed in
   129  // "FooServiceClient" to call the correct interceptors.
   130  func RegisterFooServiceHandlerClient(ctx context.Context, mux *runtime.ServeMux, client FooServiceClient) error {
   131  
   132  	mux.Handle("POST", pattern_FooService_Foo_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) {
   133  		ctx, cancel := context.WithCancel(req.Context())
   134  		defer cancel()
   135  		inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req)
   136  		var err error
   137  		var annotatedContext context.Context
   138  		annotatedContext, err = runtime.AnnotateContext(ctx, mux, req, "/grpc.gateway.examples.internal.proto.examplepb.FooService/Foo", runtime.WithHTTPPathPattern("/v1/example/foo"))
   139  		if err != nil {
   140  			runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err)
   141  			return
   142  		}
   143  		resp, md, err := request_FooService_Foo_0(annotatedContext, inboundMarshaler, client, req, pathParams)
   144  		annotatedContext = runtime.NewServerMetadataContext(annotatedContext, md)
   145  		if err != nil {
   146  			runtime.HTTPError(annotatedContext, mux, outboundMarshaler, w, req, err)
   147  			return
   148  		}
   149  
   150  		forward_FooService_Foo_0(annotatedContext, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...)
   151  
   152  	})
   153  
   154  	return nil
   155  }
   156  
   157  var (
   158  	pattern_FooService_Foo_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2}, []string{"v1", "example", "foo"}, ""))
   159  )
   160  
   161  var (
   162  	forward_FooService_Foo_0 = runtime.ForwardResponseMessage
   163  )
   164  

View as plain text