2020-08-04 00:51:19 +08:00
|
|
|
package requests
|
|
|
|
|
2020-08-05 12:14:49 +08:00
|
|
|
import (
|
2020-08-05 17:01:10 +08:00
|
|
|
"fmt"
|
2020-08-05 12:14:49 +08:00
|
|
|
"golib.gaore.com/GaoreGo/gaore-common-sdk-go/sdk/utils"
|
|
|
|
"io"
|
|
|
|
"strings"
|
|
|
|
)
|
|
|
|
|
2020-08-06 12:15:51 +08:00
|
|
|
type RpcRequest struct {
|
2020-08-04 00:51:19 +08:00
|
|
|
*baseRequest
|
|
|
|
}
|
2020-08-04 11:22:37 +08:00
|
|
|
|
2020-08-06 12:15:51 +08:00
|
|
|
func (request *RpcRequest) init() {
|
2020-08-04 12:23:34 +08:00
|
|
|
request.baseRequest = defaultBaseRequest()
|
|
|
|
request.Method = POST
|
|
|
|
}
|
|
|
|
|
2020-08-06 12:15:51 +08:00
|
|
|
func (request *RpcRequest) BuildUrl() string {
|
2020-08-05 17:01:10 +08:00
|
|
|
url := fmt.Sprintf("%s://%s", strings.ToLower(request.Scheme), request.Domain)
|
|
|
|
if len(request.Port) > 0 {
|
|
|
|
url = fmt.Sprintf("%s:%s", url, request.Port)
|
|
|
|
}
|
|
|
|
return url + request.BuildQueries()
|
2020-08-04 11:22:37 +08:00
|
|
|
}
|
|
|
|
|
2020-08-06 12:15:51 +08:00
|
|
|
func (request *RpcRequest) BuildQueries() string {
|
2020-08-05 17:01:10 +08:00
|
|
|
path := strings.TrimLeft(strings.TrimSpace(request.GetActionName()), "/")
|
|
|
|
request.queries = "/" + path + "?" + utils.GetUrlFormedMap(request.QueryParams)
|
|
|
|
return request.queries
|
2020-08-04 11:22:37 +08:00
|
|
|
}
|
2020-08-04 12:23:34 +08:00
|
|
|
|
2020-08-06 12:15:51 +08:00
|
|
|
func (request *RpcRequest) GetActionName() string {
|
2020-08-04 12:23:34 +08:00
|
|
|
return request.actionName
|
|
|
|
}
|
|
|
|
|
2020-08-06 12:15:51 +08:00
|
|
|
func (request *RpcRequest) InitWithApiInfo(domain, version, urlPath string) *RpcRequest {
|
2020-08-04 12:23:34 +08:00
|
|
|
request.init()
|
2020-08-05 17:01:10 +08:00
|
|
|
request.SetDomain(domain)
|
2020-08-04 12:23:34 +08:00
|
|
|
request.version = version
|
2020-08-05 17:01:10 +08:00
|
|
|
request.actionName = urlPath
|
2020-08-06 12:15:51 +08:00
|
|
|
return request
|
2020-08-04 12:23:34 +08:00
|
|
|
}
|
2020-08-05 12:14:49 +08:00
|
|
|
|
2020-08-06 12:15:51 +08:00
|
|
|
func (request *RpcRequest) GetBodyReader() io.Reader {
|
2020-08-05 12:14:49 +08:00
|
|
|
if request.FormParams != nil && len(request.FormParams) > 0 {
|
|
|
|
formString := utils.GetUrlFormedMap(request.FormParams)
|
|
|
|
return strings.NewReader(formString)
|
|
|
|
} else {
|
|
|
|
return strings.NewReader("")
|
|
|
|
}
|
|
|
|
}
|