選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

188 行
3.8 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. GetHeaders() map[string]string
  43. BuildUrl() string
  44. BuildQueries() string
  45. SetScheme(scheme string)
  46. SetDomain(host string)
  47. SetStringToSign(stringToSign string)
  48. GetBodyReader() io.Reader
  49. addHeaderParam(key, value string)
  50. addQueryParam(key, value string)
  51. addFormParam(key, value string)
  52. }
  53. type baseRequest struct {
  54. Scheme string
  55. Method string
  56. Host 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) GetHeaders() map[string]string {
  76. return request.Headers
  77. }
  78. func (request *baseRequest) GetActionName() string {
  79. return request.actionName
  80. }
  81. func (request *baseRequest) SetScheme(scheme string) {
  82. request.Scheme = scheme
  83. }
  84. func (request *baseRequest) SetDomain(host string) {
  85. request.Domain = host
  86. }
  87. func (request *baseRequest) GetScheme() string {
  88. return request.Scheme
  89. }
  90. func (request *baseRequest) GetDomain() string {
  91. return request.Domain
  92. }
  93. func (request *baseRequest) GetMethod() string {
  94. return request.Method
  95. }
  96. func (request *baseRequest) GetFormParams() map[string]string {
  97. return request.FormParams
  98. }
  99. func (request *baseRequest) GetQueryParams() map[string]string {
  100. return request.QueryParams
  101. }
  102. func (request *baseRequest) SetHTTPSInsecure(isInsecure bool) {
  103. request.isInsecure = &isInsecure
  104. }
  105. func (request *baseRequest) GetHTTPSInsecure() *bool {
  106. return request.isInsecure
  107. }
  108. func (request *baseRequest) GetReadTimeout() time.Duration {
  109. return request.ReadTimeout
  110. }
  111. func (request *baseRequest) GetConnectTimeout() time.Duration {
  112. return request.ConnectTimeout
  113. }
  114. func (request *baseRequest) SetReadTimeout(readTimeOut time.Duration) {
  115. request.ReadTimeout = readTimeOut
  116. }
  117. func (request *baseRequest) SetConnectTimeout(connectTimeOut time.Duration) {
  118. request.ConnectTimeout = connectTimeOut
  119. }
  120. func (request *baseRequest) SetStringToSign(stringToSign string) {
  121. request.stringToSign = stringToSign
  122. }
  123. func (request *baseRequest) addHeaderParam(key, val string) {
  124. request.Headers[key] = val
  125. }
  126. func (request *baseRequest) addQueryParam(key, val string) {
  127. request.QueryParams[key] = val
  128. }
  129. func (request *baseRequest) addFormParam(key, val string) {
  130. request.FormParams[key] = val
  131. }
  132. func defaultBaseRequest() (request *baseRequest) {
  133. request = &baseRequest{
  134. Scheme: "",
  135. AcceptFormat: "JSON",
  136. Method: GET,
  137. QueryParams: make(map[string]string),
  138. Headers: map[string]string{
  139. "x-sdk-client": "golang/1.0.0",
  140. "x-sdk-invoke-type": "normal",
  141. "Accept-Encoding": "identity",
  142. },
  143. FormParams: make(map[string]string),
  144. }
  145. return
  146. }
  147. func InitParam(request AcsRequest) (err error) {
  148. return nil
  149. }