package requests import ( "fmt" "golib.gaore.com/GaoreGo/gaore-common-sdk-go/sdk/utils" "io" "strings" ) type RpcRequest struct { *baseRequest } func (request *RpcRequest) init() { request.baseRequest = defaultBaseRequest() request.baseRequest.AddHeaderParam("Content-Type", Form) request.Method = POST } func (request *RpcRequest) BuildUrl() string { var hostname string if request.Domain.Func == nil { hostname = request.Domain.Default } else if hostname = request.Domain.Func(request.GetEnv()); hostname == "" { hostname = request.Domain.Default } url := fmt.Sprintf("%s://%s", strings.ToLower(request.Scheme), hostname) if len(request.Port) > 0 { url = fmt.Sprintf("%s:%s", url, request.Port) } return url + request.BuildQueries() } func (request *RpcRequest) GetStyle() string { return RPC } func (request *RpcRequest) BuildQueries() string { path := strings.TrimLeft(strings.TrimSpace(request.GetActionName()), "/") request.queries = "/" + path + "?" + utils.GetUrlFormedMap(request.QueryParams) return request.queries } func (request *RpcRequest) GetActionName() string { return request.actionName } func (request *RpcRequest) InitWithApiInfo(domain Host, version, urlPath string) { request.init() request.SetDomain(domain) request.version = version request.actionName = urlPath } func (request *RpcRequest) GetBodyReader() io.Reader { if request.FormParams != nil && len(request.FormParams) > 0 { formString := utils.GetUrlFormedMap(request.FormParams) return strings.NewReader(formString) } else { return strings.NewReader("") } }