github.com/tickoalcantara12/micro/v3@v3.0.0-20221007104245-9d75b9bcbab9/service/client/mucp/request.go (about)

     1  // Copyright 2020 Asim Aslam
     2  //
     3  // Licensed under the Apache License, Version 2.0 (the "License");
     4  // you may not use this file except in compliance with the License.
     5  // You may obtain a copy of the License at
     6  //
     7  //     https://www.apache.org/licenses/LICENSE-2.0
     8  //
     9  // Unless required by applicable law or agreed to in writing, software
    10  // distributed under the License is distributed on an "AS IS" BASIS,
    11  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    12  // See the License for the specific language governing permissions and
    13  // limitations under the License.
    14  //
    15  // Original source: github.com/micro/go-micro/v3/client/mucp/mucp_request.go
    16  
    17  package mucp
    18  
    19  import (
    20  	"github.com/tickoalcantara12/micro/v3/service/client"
    21  	"github.com/tickoalcantara12/micro/v3/util/codec"
    22  )
    23  
    24  type rpcRequest struct {
    25  	service     string
    26  	method      string
    27  	endpoint    string
    28  	contentType string
    29  	codec       codec.Codec
    30  	body        interface{}
    31  	opts        client.RequestOptions
    32  }
    33  
    34  func newRequest(service, endpoint string, request interface{}, contentType string, reqOpts ...client.RequestOption) client.Request {
    35  	var opts client.RequestOptions
    36  
    37  	for _, o := range reqOpts {
    38  		o(&opts)
    39  	}
    40  
    41  	// set the content-type specified
    42  	if len(opts.ContentType) > 0 {
    43  		contentType = opts.ContentType
    44  	}
    45  
    46  	return &rpcRequest{
    47  		service:     service,
    48  		method:      endpoint,
    49  		endpoint:    endpoint,
    50  		body:        request,
    51  		contentType: contentType,
    52  		opts:        opts,
    53  	}
    54  }
    55  
    56  func (r *rpcRequest) ContentType() string {
    57  	return r.contentType
    58  }
    59  
    60  func (r *rpcRequest) Service() string {
    61  	return r.service
    62  }
    63  
    64  func (r *rpcRequest) Method() string {
    65  	return r.method
    66  }
    67  
    68  func (r *rpcRequest) Endpoint() string {
    69  	return r.endpoint
    70  }
    71  
    72  func (r *rpcRequest) Body() interface{} {
    73  	return r.body
    74  }
    75  
    76  func (r *rpcRequest) Codec() codec.Writer {
    77  	return r.codec
    78  }
    79  
    80  func (r *rpcRequest) Stream() bool {
    81  	return r.opts.Stream
    82  }