micro/client/rpc_request.go

60 lines
1.0 KiB
Go
Raw Normal View History

2015-01-14 02:31:27 +03:00
package client
2019-01-10 14:39:39 +03:00
import (
"github.com/micro/go-micro/codec"
)
2015-05-23 19:40:53 +03:00
type rpcRequest struct {
2015-05-23 13:53:40 +03:00
service string
method string
contentType string
2019-01-10 14:39:39 +03:00
codec codec.Codec
body interface{}
opts RequestOptions
2015-01-14 02:31:27 +03:00
}
2018-04-14 20:06:52 +03:00
func newRequest(service, method string, request interface{}, contentType string, reqOpts ...RequestOption) Request {
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
}
2015-05-23 19:40:53 +03:00
return &rpcRequest{
2015-01-14 02:31:27 +03:00
service: service,
method: method,
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
}
}
2015-05-23 19:40:53 +03:00
func (r *rpcRequest) ContentType() string {
2015-01-14 02:31:27 +03:00
return r.contentType
}
2015-05-23 19:40:53 +03:00
func (r *rpcRequest) Service() string {
2015-01-14 02:31:27 +03:00
return r.service
}
2015-05-23 19:40:53 +03:00
func (r *rpcRequest) Method() string {
2015-01-14 02:31:27 +03:00
return r.method
}
2019-01-10 14:39:39 +03:00
func (r *rpcRequest) Body() interface{} {
return r.body
}
func (r *rpcRequest) Codec() codec.Writer {
return r.codec
2015-01-14 02:31:27 +03:00
}
2015-12-17 23:37:35 +03:00
func (r *rpcRequest) Stream() bool {
return r.opts.Stream
2015-12-17 23:37:35 +03:00
}