rpc_request.go 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. /*
  2. * Licensed under the Apache License, Version 2.0 (the "License");
  3. * you may not use this file except in compliance with the License.
  4. * You may obtain a copy of the License at
  5. *
  6. * http://www.apache.org/licenses/LICENSE-2.0
  7. *
  8. * Unless required by applicable law or agreed to in writing, software
  9. * distributed under the License is distributed on an "AS IS" BASIS,
  10. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  11. * See the License for the specific language governing permissions and
  12. * limitations under the License.
  13. */
  14. package requests
  15. import (
  16. "fmt"
  17. "io"
  18. "strings"
  19. "github.com/aliyun/alibaba-cloud-sdk-go/sdk/utils"
  20. )
  21. type RpcRequest struct {
  22. *baseRequest
  23. }
  24. func (request *RpcRequest) init() {
  25. request.baseRequest = defaultBaseRequest()
  26. request.Method = POST
  27. }
  28. func (*RpcRequest) GetStyle() string {
  29. return RPC
  30. }
  31. func (request *RpcRequest) GetBodyReader() io.Reader {
  32. if request.FormParams != nil && len(request.FormParams) > 0 {
  33. formString := utils.GetUrlFormedMap(request.FormParams)
  34. return strings.NewReader(formString)
  35. } else {
  36. return strings.NewReader("")
  37. }
  38. }
  39. func (request *RpcRequest) BuildQueries() string {
  40. request.queries = "/?" + utils.GetUrlFormedMap(request.QueryParams)
  41. return request.queries
  42. }
  43. func (request *RpcRequest) BuildUrl() string {
  44. url := fmt.Sprintf("%s://%s", strings.ToLower(request.Scheme), request.Domain)
  45. if len(request.Port) > 0 {
  46. url = fmt.Sprintf("%s:%s", url, request.Port)
  47. }
  48. return url + request.BuildQueries()
  49. }
  50. func (request *RpcRequest) GetVersion() string {
  51. return request.version
  52. }
  53. func (request *RpcRequest) GetActionName() string {
  54. return request.actionName
  55. }
  56. func (request *RpcRequest) addPathParam(key, value string) {
  57. panic("not support")
  58. }
  59. func (request *RpcRequest) InitWithApiInfo(product, version, action, serviceCode, endpointType string) {
  60. request.init()
  61. request.product = product
  62. request.version = version
  63. request.actionName = action
  64. request.locationServiceCode = serviceCode
  65. request.locationEndpointType = endpointType
  66. }