...

Source file src/github.com/grpc-ecosystem/grpc-gateway/v2/examples/internal/proto/examplepb/non_standard_names.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/non_standard_names.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  var (
    35  	filter_NonStandardService_Update_0 = &utilities.DoubleArray{Encoding: map[string]int{"body": 0}, Base: []int{1, 1, 0}, Check: []int{0, 1, 2}}
    36  )
    37  
    38  func request_NonStandardService_Update_0(ctx context.Context, marshaler runtime.Marshaler, client NonStandardServiceClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) {
    39  	var protoReq NonStandardUpdateRequest
    40  	var metadata runtime.ServerMetadata
    41  
    42  	newReader, berr := utilities.IOReaderFactory(req.Body)
    43  	if berr != nil {
    44  		return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", berr)
    45  	}
    46  	if err := marshaler.NewDecoder(newReader()).Decode(&protoReq.Body); err != nil && err != io.EOF {
    47  		return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err)
    48  	}
    49  	if protoReq.UpdateMask == nil || len(protoReq.UpdateMask.GetPaths()) == 0 {
    50  		if fieldMask, err := runtime.FieldMaskFromRequestBody(newReader(), protoReq.Body); err != nil {
    51  			return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err)
    52  		} else {
    53  			protoReq.UpdateMask = fieldMask
    54  		}
    55  	}
    56  
    57  	if err := req.ParseForm(); err != nil {
    58  		return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err)
    59  	}
    60  	if err := runtime.PopulateQueryParameters(&protoReq, req.Form, filter_NonStandardService_Update_0); err != nil {
    61  		return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err)
    62  	}
    63  
    64  	msg, err := client.Update(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD))
    65  	return msg, metadata, err
    66  
    67  }
    68  
    69  func local_request_NonStandardService_Update_0(ctx context.Context, marshaler runtime.Marshaler, server NonStandardServiceServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) {
    70  	var protoReq NonStandardUpdateRequest
    71  	var metadata runtime.ServerMetadata
    72  
    73  	newReader, berr := utilities.IOReaderFactory(req.Body)
    74  	if berr != nil {
    75  		return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", berr)
    76  	}
    77  	if err := marshaler.NewDecoder(newReader()).Decode(&protoReq.Body); err != nil && err != io.EOF {
    78  		return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err)
    79  	}
    80  	if protoReq.UpdateMask == nil || len(protoReq.UpdateMask.GetPaths()) == 0 {
    81  		if fieldMask, err := runtime.FieldMaskFromRequestBody(newReader(), protoReq.Body); err != nil {
    82  			return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err)
    83  		} else {
    84  			protoReq.UpdateMask = fieldMask
    85  		}
    86  	}
    87  
    88  	if err := req.ParseForm(); err != nil {
    89  		return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err)
    90  	}
    91  	if err := runtime.PopulateQueryParameters(&protoReq, req.Form, filter_NonStandardService_Update_0); err != nil {
    92  		return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err)
    93  	}
    94  
    95  	msg, err := server.Update(ctx, &protoReq)
    96  	return msg, metadata, err
    97  
    98  }
    99  
   100  var (
   101  	filter_NonStandardService_UpdateWithJSONNames_0 = &utilities.DoubleArray{Encoding: map[string]int{"body": 0}, Base: []int{1, 1, 0}, Check: []int{0, 1, 2}}
   102  )
   103  
   104  func request_NonStandardService_UpdateWithJSONNames_0(ctx context.Context, marshaler runtime.Marshaler, client NonStandardServiceClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) {
   105  	var protoReq NonStandardWithJSONNamesUpdateRequest
   106  	var metadata runtime.ServerMetadata
   107  
   108  	newReader, berr := utilities.IOReaderFactory(req.Body)
   109  	if berr != nil {
   110  		return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", berr)
   111  	}
   112  	if err := marshaler.NewDecoder(newReader()).Decode(&protoReq.Body); err != nil && err != io.EOF {
   113  		return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err)
   114  	}
   115  	if protoReq.UpdateMask == nil || len(protoReq.UpdateMask.GetPaths()) == 0 {
   116  		if fieldMask, err := runtime.FieldMaskFromRequestBody(newReader(), protoReq.Body); err != nil {
   117  			return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err)
   118  		} else {
   119  			protoReq.UpdateMask = fieldMask
   120  		}
   121  	}
   122  
   123  	if err := req.ParseForm(); err != nil {
   124  		return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err)
   125  	}
   126  	if err := runtime.PopulateQueryParameters(&protoReq, req.Form, filter_NonStandardService_UpdateWithJSONNames_0); err != nil {
   127  		return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err)
   128  	}
   129  
   130  	msg, err := client.UpdateWithJSONNames(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD))
   131  	return msg, metadata, err
   132  
   133  }
   134  
   135  func local_request_NonStandardService_UpdateWithJSONNames_0(ctx context.Context, marshaler runtime.Marshaler, server NonStandardServiceServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) {
   136  	var protoReq NonStandardWithJSONNamesUpdateRequest
   137  	var metadata runtime.ServerMetadata
   138  
   139  	newReader, berr := utilities.IOReaderFactory(req.Body)
   140  	if berr != nil {
   141  		return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", berr)
   142  	}
   143  	if err := marshaler.NewDecoder(newReader()).Decode(&protoReq.Body); err != nil && err != io.EOF {
   144  		return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err)
   145  	}
   146  	if protoReq.UpdateMask == nil || len(protoReq.UpdateMask.GetPaths()) == 0 {
   147  		if fieldMask, err := runtime.FieldMaskFromRequestBody(newReader(), protoReq.Body); err != nil {
   148  			return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err)
   149  		} else {
   150  			protoReq.UpdateMask = fieldMask
   151  		}
   152  	}
   153  
   154  	if err := req.ParseForm(); err != nil {
   155  		return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err)
   156  	}
   157  	if err := runtime.PopulateQueryParameters(&protoReq, req.Form, filter_NonStandardService_UpdateWithJSONNames_0); err != nil {
   158  		return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err)
   159  	}
   160  
   161  	msg, err := server.UpdateWithJSONNames(ctx, &protoReq)
   162  	return msg, metadata, err
   163  
   164  }
   165  
   166  // RegisterNonStandardServiceHandlerServer registers the http handlers for service NonStandardService to "mux".
   167  // UnaryRPC     :call NonStandardServiceServer directly.
   168  // StreamingRPC :currently unsupported pending https://github.com/grpc/grpc-go/issues/906.
   169  // Note that using this registration option will cause many gRPC library features to stop working. Consider using RegisterNonStandardServiceHandlerFromEndpoint instead.
   170  func RegisterNonStandardServiceHandlerServer(ctx context.Context, mux *runtime.ServeMux, server NonStandardServiceServer) error {
   171  
   172  	mux.Handle("PATCH", pattern_NonStandardService_Update_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) {
   173  		ctx, cancel := context.WithCancel(req.Context())
   174  		defer cancel()
   175  		var stream runtime.ServerTransportStream
   176  		ctx = grpc.NewContextWithServerTransportStream(ctx, &stream)
   177  		inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req)
   178  		var err error
   179  		var annotatedContext context.Context
   180  		annotatedContext, err = runtime.AnnotateIncomingContext(ctx, mux, req, "/grpc.gateway.examples.internal.proto.examplepb.NonStandardService/Update", runtime.WithHTTPPathPattern("/v1/example/non_standard/update"))
   181  		if err != nil {
   182  			runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err)
   183  			return
   184  		}
   185  		resp, md, err := local_request_NonStandardService_Update_0(annotatedContext, inboundMarshaler, server, req, pathParams)
   186  		md.HeaderMD, md.TrailerMD = metadata.Join(md.HeaderMD, stream.Header()), metadata.Join(md.TrailerMD, stream.Trailer())
   187  		annotatedContext = runtime.NewServerMetadataContext(annotatedContext, md)
   188  		if err != nil {
   189  			runtime.HTTPError(annotatedContext, mux, outboundMarshaler, w, req, err)
   190  			return
   191  		}
   192  
   193  		forward_NonStandardService_Update_0(annotatedContext, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...)
   194  
   195  	})
   196  
   197  	mux.Handle("PATCH", pattern_NonStandardService_UpdateWithJSONNames_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) {
   198  		ctx, cancel := context.WithCancel(req.Context())
   199  		defer cancel()
   200  		var stream runtime.ServerTransportStream
   201  		ctx = grpc.NewContextWithServerTransportStream(ctx, &stream)
   202  		inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req)
   203  		var err error
   204  		var annotatedContext context.Context
   205  		annotatedContext, err = runtime.AnnotateIncomingContext(ctx, mux, req, "/grpc.gateway.examples.internal.proto.examplepb.NonStandardService/UpdateWithJSONNames", runtime.WithHTTPPathPattern("/v1/example/non_standard/update_with_json_names"))
   206  		if err != nil {
   207  			runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err)
   208  			return
   209  		}
   210  		resp, md, err := local_request_NonStandardService_UpdateWithJSONNames_0(annotatedContext, inboundMarshaler, server, req, pathParams)
   211  		md.HeaderMD, md.TrailerMD = metadata.Join(md.HeaderMD, stream.Header()), metadata.Join(md.TrailerMD, stream.Trailer())
   212  		annotatedContext = runtime.NewServerMetadataContext(annotatedContext, md)
   213  		if err != nil {
   214  			runtime.HTTPError(annotatedContext, mux, outboundMarshaler, w, req, err)
   215  			return
   216  		}
   217  
   218  		forward_NonStandardService_UpdateWithJSONNames_0(annotatedContext, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...)
   219  
   220  	})
   221  
   222  	return nil
   223  }
   224  
   225  // RegisterNonStandardServiceHandlerFromEndpoint is same as RegisterNonStandardServiceHandler but
   226  // automatically dials to "endpoint" and closes the connection when "ctx" gets done.
   227  func RegisterNonStandardServiceHandlerFromEndpoint(ctx context.Context, mux *runtime.ServeMux, endpoint string, opts []grpc.DialOption) (err error) {
   228  	conn, err := grpc.DialContext(ctx, endpoint, opts...)
   229  	if err != nil {
   230  		return err
   231  	}
   232  	defer func() {
   233  		if err != nil {
   234  			if cerr := conn.Close(); cerr != nil {
   235  				grpclog.Infof("Failed to close conn to %s: %v", endpoint, cerr)
   236  			}
   237  			return
   238  		}
   239  		go func() {
   240  			<-ctx.Done()
   241  			if cerr := conn.Close(); cerr != nil {
   242  				grpclog.Infof("Failed to close conn to %s: %v", endpoint, cerr)
   243  			}
   244  		}()
   245  	}()
   246  
   247  	return RegisterNonStandardServiceHandler(ctx, mux, conn)
   248  }
   249  
   250  // RegisterNonStandardServiceHandler registers the http handlers for service NonStandardService to "mux".
   251  // The handlers forward requests to the grpc endpoint over "conn".
   252  func RegisterNonStandardServiceHandler(ctx context.Context, mux *runtime.ServeMux, conn *grpc.ClientConn) error {
   253  	return RegisterNonStandardServiceHandlerClient(ctx, mux, NewNonStandardServiceClient(conn))
   254  }
   255  
   256  // RegisterNonStandardServiceHandlerClient registers the http handlers for service NonStandardService
   257  // to "mux". The handlers forward requests to the grpc endpoint over the given implementation of "NonStandardServiceClient".
   258  // Note: the gRPC framework executes interceptors within the gRPC handler. If the passed in "NonStandardServiceClient"
   259  // doesn't go through the normal gRPC flow (creating a gRPC client etc.) then it will be up to the passed in
   260  // "NonStandardServiceClient" to call the correct interceptors.
   261  func RegisterNonStandardServiceHandlerClient(ctx context.Context, mux *runtime.ServeMux, client NonStandardServiceClient) error {
   262  
   263  	mux.Handle("PATCH", pattern_NonStandardService_Update_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) {
   264  		ctx, cancel := context.WithCancel(req.Context())
   265  		defer cancel()
   266  		inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req)
   267  		var err error
   268  		var annotatedContext context.Context
   269  		annotatedContext, err = runtime.AnnotateContext(ctx, mux, req, "/grpc.gateway.examples.internal.proto.examplepb.NonStandardService/Update", runtime.WithHTTPPathPattern("/v1/example/non_standard/update"))
   270  		if err != nil {
   271  			runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err)
   272  			return
   273  		}
   274  		resp, md, err := request_NonStandardService_Update_0(annotatedContext, inboundMarshaler, client, req, pathParams)
   275  		annotatedContext = runtime.NewServerMetadataContext(annotatedContext, md)
   276  		if err != nil {
   277  			runtime.HTTPError(annotatedContext, mux, outboundMarshaler, w, req, err)
   278  			return
   279  		}
   280  
   281  		forward_NonStandardService_Update_0(annotatedContext, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...)
   282  
   283  	})
   284  
   285  	mux.Handle("PATCH", pattern_NonStandardService_UpdateWithJSONNames_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) {
   286  		ctx, cancel := context.WithCancel(req.Context())
   287  		defer cancel()
   288  		inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req)
   289  		var err error
   290  		var annotatedContext context.Context
   291  		annotatedContext, err = runtime.AnnotateContext(ctx, mux, req, "/grpc.gateway.examples.internal.proto.examplepb.NonStandardService/UpdateWithJSONNames", runtime.WithHTTPPathPattern("/v1/example/non_standard/update_with_json_names"))
   292  		if err != nil {
   293  			runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err)
   294  			return
   295  		}
   296  		resp, md, err := request_NonStandardService_UpdateWithJSONNames_0(annotatedContext, inboundMarshaler, client, req, pathParams)
   297  		annotatedContext = runtime.NewServerMetadataContext(annotatedContext, md)
   298  		if err != nil {
   299  			runtime.HTTPError(annotatedContext, mux, outboundMarshaler, w, req, err)
   300  			return
   301  		}
   302  
   303  		forward_NonStandardService_UpdateWithJSONNames_0(annotatedContext, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...)
   304  
   305  	})
   306  
   307  	return nil
   308  }
   309  
   310  var (
   311  	pattern_NonStandardService_Update_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 2, 3}, []string{"v1", "example", "non_standard", "update"}, ""))
   312  
   313  	pattern_NonStandardService_UpdateWithJSONNames_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 2, 3}, []string{"v1", "example", "non_standard", "update_with_json_names"}, ""))
   314  )
   315  
   316  var (
   317  	forward_NonStandardService_Update_0 = runtime.ForwardResponseMessage
   318  
   319  	forward_NonStandardService_UpdateWithJSONNames_0 = runtime.ForwardResponseMessage
   320  )
   321  

View as plain text