You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

192 lines
3.9 KiB

  1. package requests
  2. import (
  3. "io"
  4. "time"
  5. )
  6. const (
  7. RPC = "RPC"
  8. ROA = "ROA"
  9. HTTP = "HTTP"
  10. HTTPS = "HTTPS"
  11. DefaultHttpPort = "80"
  12. GET = "GET"
  13. PUT = "PUT"
  14. POST = "POST"
  15. DELETE = "DELETE"
  16. PATCH = "PATCH"
  17. HEAD = "HEAD"
  18. OPTIONS = "OPTIONS"
  19. Json = "application/json"
  20. Xml = "application/xml"
  21. Raw = "application/octet-stream"
  22. Form = "application/x-www-form-urlencoded"
  23. Header = "Header"
  24. Query = "Query"
  25. Body = "Body"
  26. Path = "Path"
  27. HeaderSeparator = "\n"
  28. )
  29. type AcsRequest interface {
  30. GetReadTimeout() time.Duration
  31. GetConnectTimeout() time.Duration
  32. SetReadTimeout(readTimeOut time.Duration)
  33. SetConnectTimeout(connectTimeOut time.Duration)
  34. SetHTTPSInsecure(isInsecure bool)
  35. GetHTTPSInsecure() *bool
  36. GetQueryParams() map[string]string
  37. GetFormParams() map[string]string
  38. GetMethod() string
  39. GetScheme() string
  40. GetDomain() string
  41. GetActionName() string
  42. GetAcceptFormat() string
  43. GetHeaders() map[string]string
  44. BuildUrl() string
  45. BuildQueries() string
  46. SetScheme(scheme string)
  47. SetDomain(host string)
  48. SetStringToSign(stringToSign string)
  49. GetBodyReader() io.Reader
  50. addHeaderParam(key, value string)
  51. addQueryParam(key, value string)
  52. addFormParam(key, value string)
  53. }
  54. type baseRequest struct {
  55. Scheme string
  56. Method string
  57. Port string
  58. Domain string
  59. From string
  60. ReadTimeout time.Duration
  61. ConnectTimeout time.Duration
  62. isInsecure *bool
  63. AcceptFormat string
  64. actionName string
  65. userAgent map[string]string
  66. product string
  67. version string
  68. QueryParams map[string]string
  69. Headers map[string]string
  70. FormParams map[string]string
  71. Content []byte
  72. queries string
  73. stringToSign string
  74. }
  75. func (request *baseRequest) GetAcceptFormat() string {
  76. return request.AcceptFormat
  77. }
  78. func (request *baseRequest) GetHeaders() map[string]string {
  79. return request.Headers
  80. }
  81. func (request *baseRequest) GetActionName() string {
  82. return request.actionName
  83. }
  84. func (request *baseRequest) SetScheme(scheme string) {
  85. request.Scheme = scheme
  86. }
  87. func (request *baseRequest) SetDomain(host string) {
  88. request.Domain = host
  89. }
  90. func (request *baseRequest) GetScheme() string {
  91. return request.Scheme
  92. }
  93. func (request *baseRequest) GetDomain() string {
  94. return request.Domain
  95. }
  96. func (request *baseRequest) GetMethod() string {
  97. return request.Method
  98. }
  99. func (request *baseRequest) GetFormParams() map[string]string {
  100. return request.FormParams
  101. }
  102. func (request *baseRequest) GetQueryParams() map[string]string {
  103. return request.QueryParams
  104. }
  105. func (request *baseRequest) SetHTTPSInsecure(isInsecure bool) {
  106. request.isInsecure = &isInsecure
  107. }
  108. func (request *baseRequest) GetHTTPSInsecure() *bool {
  109. return request.isInsecure
  110. }
  111. func (request *baseRequest) GetReadTimeout() time.Duration {
  112. return request.ReadTimeout
  113. }
  114. func (request *baseRequest) GetConnectTimeout() time.Duration {
  115. return request.ConnectTimeout
  116. }
  117. func (request *baseRequest) SetReadTimeout(readTimeOut time.Duration) {
  118. request.ReadTimeout = readTimeOut
  119. }
  120. func (request *baseRequest) SetConnectTimeout(connectTimeOut time.Duration) {
  121. request.ConnectTimeout = connectTimeOut
  122. }
  123. func (request *baseRequest) SetStringToSign(stringToSign string) {
  124. request.stringToSign = stringToSign
  125. }
  126. func (request *baseRequest) addHeaderParam(key, val string) {
  127. request.Headers[key] = val
  128. }
  129. func (request *baseRequest) addQueryParam(key, val string) {
  130. request.QueryParams[key] = val
  131. }
  132. func (request *baseRequest) addFormParam(key, val string) {
  133. request.FormParams[key] = val
  134. }
  135. func defaultBaseRequest() (request *baseRequest) {
  136. request = &baseRequest{
  137. Scheme: HTTP,
  138. AcceptFormat: "JSON",
  139. Method: GET,
  140. QueryParams: make(map[string]string),
  141. Headers: map[string]string{
  142. "x-sdk-client": "golang/1.0.0",
  143. "x-sdk-invoke-type": "normal",
  144. "Accept-Encoding": "identity",
  145. },
  146. FormParams: make(map[string]string),
  147. }
  148. return
  149. }
  150. func InitParam(request AcsRequest) (err error) {
  151. return nil
  152. }