2015-01-14 01:31:27 +02:00
|
|
|
package client
|
|
|
|
|
2019-01-10 13:39:39 +02:00
|
|
|
import (
|
2021-01-20 15:54:31 +02:00
|
|
|
"github.com/asim/go-micro/v3/codec"
|
2019-01-10 13:39:39 +02:00
|
|
|
)
|
|
|
|
|
2015-05-23 18:40:53 +02:00
|
|
|
type rpcRequest struct {
|
2015-05-23 12:53:40 +02:00
|
|
|
service string
|
2019-01-18 14:30:39 +02:00
|
|
|
method string
|
2019-01-10 23:25:31 +02:00
|
|
|
endpoint string
|
2015-05-23 12:53:40 +02:00
|
|
|
contentType string
|
2019-01-10 13:39:39 +02:00
|
|
|
codec codec.Codec
|
|
|
|
body interface{}
|
2015-12-31 20:11:46 +02:00
|
|
|
opts RequestOptions
|
2015-01-14 01:31:27 +02:00
|
|
|
}
|
|
|
|
|
2019-01-10 23:25:31 +02:00
|
|
|
func newRequest(service, endpoint string, request interface{}, contentType string, reqOpts ...RequestOption) Request {
|
2015-12-31 20:11:46 +02:00
|
|
|
var opts RequestOptions
|
2015-12-17 22:37:35 +02:00
|
|
|
|
|
|
|
for _, o := range reqOpts {
|
|
|
|
o(&opts)
|
|
|
|
}
|
|
|
|
|
2018-04-14 19:06:52 +02:00
|
|
|
// set the content-type specified
|
|
|
|
if len(opts.ContentType) > 0 {
|
|
|
|
contentType = opts.ContentType
|
|
|
|
}
|
|
|
|
|
2015-05-23 18:40:53 +02:00
|
|
|
return &rpcRequest{
|
2015-01-14 01:31:27 +02:00
|
|
|
service: service,
|
2019-01-18 14:30:39 +02:00
|
|
|
method: endpoint,
|
2019-01-10 23:25:31 +02:00
|
|
|
endpoint: endpoint,
|
2019-01-10 13:39:39 +02:00
|
|
|
body: request,
|
2015-01-14 01:31:27 +02:00
|
|
|
contentType: contentType,
|
2015-12-17 22:37:35 +02:00
|
|
|
opts: opts,
|
2015-01-14 01:31:27 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-05-23 18:40:53 +02:00
|
|
|
func (r *rpcRequest) ContentType() string {
|
2015-01-14 01:31:27 +02:00
|
|
|
return r.contentType
|
|
|
|
}
|
|
|
|
|
2015-05-23 18:40:53 +02:00
|
|
|
func (r *rpcRequest) Service() string {
|
2015-01-14 01:31:27 +02:00
|
|
|
return r.service
|
|
|
|
}
|
|
|
|
|
2019-01-18 12:12:57 +02:00
|
|
|
func (r *rpcRequest) Method() string {
|
|
|
|
return r.method
|
|
|
|
}
|
|
|
|
|
2019-01-10 23:25:31 +02:00
|
|
|
func (r *rpcRequest) Endpoint() string {
|
|
|
|
return r.endpoint
|
2015-01-14 01:31:27 +02:00
|
|
|
}
|
|
|
|
|
2019-01-10 13:39:39 +02:00
|
|
|
func (r *rpcRequest) Body() interface{} {
|
|
|
|
return r.body
|
|
|
|
}
|
|
|
|
|
|
|
|
func (r *rpcRequest) Codec() codec.Writer {
|
|
|
|
return r.codec
|
2015-01-14 01:31:27 +02:00
|
|
|
}
|
2015-12-17 22:37:35 +02:00
|
|
|
|
|
|
|
func (r *rpcRequest) Stream() bool {
|
2015-12-31 20:11:46 +02:00
|
|
|
return r.opts.Stream
|
2015-12-17 22:37:35 +02:00
|
|
|
}
|