github.com/kaydxh/golang@v0.0.131/pkg/grpc-gateway/date/date.pb.gw.go (about)

     1  /*
     2   *Copyright (c) 2022, kaydxh
     3   *
     4   *Permission is hereby granted, free of charge, to any person obtaining a copy
     5   *of this software and associated documentation files (the "Software"), to deal
     6   *in the Software without restriction, including without limitation the rights
     7   *to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
     8   *copies of the Software, and to permit persons to whom the Software is
     9   *furnished to do so, subject to the following conditions:
    10   *
    11   *The above copyright notice and this permission notice shall be included in all
    12   *copies or substantial portions of the Software.
    13   *
    14   *THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
    15   *IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
    16   *FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
    17   *AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
    18   *LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
    19   *OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
    20   *SOFTWARE.
    21   */
    22  // Code generated by protoc-gen-grpc-gateway. DO NOT EDIT.
    23  // source: date/date.proto
    24  
    25  /*
    26  Package date is a reverse proxy.
    27  
    28  It translates gRPC into RESTful JSON APIs.
    29  */
    30  package date
    31  
    32  import (
    33  	"context"
    34  	"io"
    35  	"net/http"
    36  
    37  	"github.com/grpc-ecosystem/grpc-gateway/v2/runtime"
    38  	"github.com/grpc-ecosystem/grpc-gateway/v2/utilities"
    39  	"google.golang.org/grpc"
    40  	"google.golang.org/grpc/codes"
    41  	"google.golang.org/grpc/grpclog"
    42  	"google.golang.org/grpc/metadata"
    43  	"google.golang.org/grpc/status"
    44  	"google.golang.org/protobuf/proto"
    45  )
    46  
    47  // Suppress "imported and not used" errors
    48  var _ codes.Code
    49  var _ io.Reader
    50  var _ status.Status
    51  var _ = runtime.String
    52  var _ = utilities.NewDoubleArray
    53  var _ = metadata.Join
    54  
    55  func request_DateService_Now_0(ctx context.Context, marshaler runtime.Marshaler, client DateServiceClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) {
    56  	var protoReq DateRequest
    57  	var metadata runtime.ServerMetadata
    58  
    59  	newReader, berr := utilities.IOReaderFactory(req.Body)
    60  	if berr != nil {
    61  		return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", berr)
    62  	}
    63  	if err := marshaler.NewDecoder(newReader()).Decode(&protoReq); err != nil && err != io.EOF {
    64  		return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err)
    65  	}
    66  
    67  	msg, err := client.Now(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD))
    68  	return msg, metadata, err
    69  
    70  }
    71  
    72  func local_request_DateService_Now_0(ctx context.Context, marshaler runtime.Marshaler, server DateServiceServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) {
    73  	var protoReq DateRequest
    74  	var metadata runtime.ServerMetadata
    75  
    76  	newReader, berr := utilities.IOReaderFactory(req.Body)
    77  	if berr != nil {
    78  		return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", berr)
    79  	}
    80  	if err := marshaler.NewDecoder(newReader()).Decode(&protoReq); err != nil && err != io.EOF {
    81  		return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err)
    82  	}
    83  
    84  	msg, err := server.Now(ctx, &protoReq)
    85  	return msg, metadata, err
    86  
    87  }
    88  
    89  // RegisterDateServiceHandlerServer registers the http handlers for service DateService to "mux".
    90  // UnaryRPC     :call DateServiceServer directly.
    91  // StreamingRPC :currently unsupported pending https://github.com/grpc/grpc-go/issues/906.
    92  // Note that using this registration option will cause many gRPC library features to stop working. Consider using RegisterDateServiceHandlerFromEndpoint instead.
    93  func RegisterDateServiceHandlerServer(ctx context.Context, mux *runtime.ServeMux, server DateServiceServer) error {
    94  
    95  	mux.Handle("POST", pattern_DateService_Now_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) {
    96  		ctx, cancel := context.WithCancel(req.Context())
    97  		defer cancel()
    98  		var stream runtime.ServerTransportStream
    99  		ctx = grpc.NewContextWithServerTransportStream(ctx, &stream)
   100  		inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req)
   101  		rctx, err := runtime.AnnotateIncomingContext(ctx, mux, req, "/sea.api.v1.date.DateService/Now", runtime.WithHTTPPathPattern("/Now"))
   102  		if err != nil {
   103  			runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err)
   104  			return
   105  		}
   106  		resp, md, err := local_request_DateService_Now_0(rctx, inboundMarshaler, server, req, pathParams)
   107  		md.HeaderMD, md.TrailerMD = metadata.Join(md.HeaderMD, stream.Header()), metadata.Join(md.TrailerMD, stream.Trailer())
   108  		ctx = runtime.NewServerMetadataContext(ctx, md)
   109  		if err != nil {
   110  			runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err)
   111  			return
   112  		}
   113  
   114  		forward_DateService_Now_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...)
   115  
   116  	})
   117  
   118  	return nil
   119  }
   120  
   121  // RegisterDateServiceHandlerFromEndpoint is same as RegisterDateServiceHandler but
   122  // automatically dials to "endpoint" and closes the connection when "ctx" gets done.
   123  func RegisterDateServiceHandlerFromEndpoint(ctx context.Context, mux *runtime.ServeMux, endpoint string, opts []grpc.DialOption) (err error) {
   124  	conn, err := grpc.Dial(endpoint, opts...)
   125  	if err != nil {
   126  		return err
   127  	}
   128  	defer func() {
   129  		if err != nil {
   130  			if cerr := conn.Close(); cerr != nil {
   131  				grpclog.Infof("Failed to close conn to %s: %v", endpoint, cerr)
   132  			}
   133  			return
   134  		}
   135  		go func() {
   136  			<-ctx.Done()
   137  			if cerr := conn.Close(); cerr != nil {
   138  				grpclog.Infof("Failed to close conn to %s: %v", endpoint, cerr)
   139  			}
   140  		}()
   141  	}()
   142  
   143  	return RegisterDateServiceHandler(ctx, mux, conn)
   144  }
   145  
   146  // RegisterDateServiceHandler registers the http handlers for service DateService to "mux".
   147  // The handlers forward requests to the grpc endpoint over "conn".
   148  func RegisterDateServiceHandler(ctx context.Context, mux *runtime.ServeMux, conn *grpc.ClientConn) error {
   149  	return RegisterDateServiceHandlerClient(ctx, mux, NewDateServiceClient(conn))
   150  }
   151  
   152  // RegisterDateServiceHandlerClient registers the http handlers for service DateService
   153  // to "mux". The handlers forward requests to the grpc endpoint over the given implementation of "DateServiceClient".
   154  // Note: the gRPC framework executes interceptors within the gRPC handler. If the passed in "DateServiceClient"
   155  // doesn't go through the normal gRPC flow (creating a gRPC client etc.) then it will be up to the passed in
   156  // "DateServiceClient" to call the correct interceptors.
   157  func RegisterDateServiceHandlerClient(ctx context.Context, mux *runtime.ServeMux, client DateServiceClient) error {
   158  
   159  	mux.Handle("POST", pattern_DateService_Now_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) {
   160  		ctx, cancel := context.WithCancel(req.Context())
   161  		defer cancel()
   162  		inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req)
   163  		rctx, err := runtime.AnnotateContext(ctx, mux, req, "/sea.api.v1.date.DateService/Now", runtime.WithHTTPPathPattern("/Now"))
   164  		if err != nil {
   165  			runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err)
   166  			return
   167  		}
   168  		resp, md, err := request_DateService_Now_0(rctx, inboundMarshaler, client, req, pathParams)
   169  		ctx = runtime.NewServerMetadataContext(ctx, md)
   170  		if err != nil {
   171  			runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err)
   172  			return
   173  		}
   174  
   175  		forward_DateService_Now_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...)
   176  
   177  	})
   178  
   179  	return nil
   180  }
   181  
   182  var (
   183  	pattern_DateService_Now_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0}, []string{"Now"}, ""))
   184  )
   185  
   186  var (
   187  	forward_DateService_Now_0 = runtime.ForwardResponseMessage
   188  )