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