2017-01-01 21:39:05 +03:00
|
|
|
package http
|
|
|
|
|
|
|
|
import (
|
2021-01-10 14:48:10 +03:00
|
|
|
"github.com/unistack-org/micro/v3/client"
|
|
|
|
"github.com/unistack-org/micro/v3/codec"
|
2017-01-01 21:39:05 +03:00
|
|
|
)
|
|
|
|
|
|
|
|
type httpRequest struct {
|
|
|
|
service string
|
|
|
|
method string
|
|
|
|
contentType string
|
|
|
|
request interface{}
|
|
|
|
opts client.RequestOptions
|
|
|
|
}
|
|
|
|
|
2021-01-10 14:48:10 +03:00
|
|
|
func newHTTPRequest(service, method string, request interface{}, contentType string, opts ...client.RequestOption) client.Request {
|
|
|
|
options := client.NewRequestOptions(opts...)
|
2017-01-01 21:39:05 +03:00
|
|
|
|
2021-01-10 14:48:10 +03:00
|
|
|
if len(options.ContentType) == 0 {
|
|
|
|
options.ContentType = contentType
|
2018-04-17 14:12:51 +03:00
|
|
|
}
|
|
|
|
|
2017-01-01 21:39:05 +03:00
|
|
|
return &httpRequest{
|
|
|
|
service: service,
|
|
|
|
method: method,
|
|
|
|
request: request,
|
2021-01-10 14:48:10 +03:00
|
|
|
contentType: options.ContentType,
|
|
|
|
opts: options,
|
2017-01-01 21:39:05 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (h *httpRequest) ContentType() string {
|
|
|
|
return h.contentType
|
|
|
|
}
|
|
|
|
|
|
|
|
func (h *httpRequest) Service() string {
|
|
|
|
return h.service
|
|
|
|
}
|
|
|
|
|
2019-01-18 18:47:50 +03:00
|
|
|
func (h *httpRequest) Method() string {
|
|
|
|
return h.method
|
|
|
|
}
|
|
|
|
|
2019-01-11 01:12:43 +03:00
|
|
|
func (h *httpRequest) Endpoint() string {
|
2017-01-01 21:39:05 +03:00
|
|
|
return h.method
|
|
|
|
}
|
|
|
|
|
2021-01-10 14:48:10 +03:00
|
|
|
func (h *httpRequest) Codec() codec.Codec {
|
2019-01-10 14:59:45 +03:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (h *httpRequest) Body() interface{} {
|
2017-01-01 21:39:05 +03:00
|
|
|
return h.request
|
|
|
|
}
|
|
|
|
|
|
|
|
func (h *httpRequest) Stream() bool {
|
|
|
|
return h.opts.Stream
|
|
|
|
}
|