type.go 47 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080
  1. package oss
  2. import (
  3. "encoding/base64"
  4. "encoding/xml"
  5. "fmt"
  6. "net/url"
  7. "time"
  8. )
  9. // ListBucketsResult defines the result object from ListBuckets request
  10. type ListBucketsResult struct {
  11. XMLName xml.Name `xml:"ListAllMyBucketsResult"`
  12. Prefix string `xml:"Prefix"` // The prefix in this query
  13. Marker string `xml:"Marker"` // The marker filter
  14. MaxKeys int `xml:"MaxKeys"` // The max entry count to return. This information is returned when IsTruncated is true.
  15. IsTruncated bool `xml:"IsTruncated"` // Flag true means there's remaining buckets to return.
  16. NextMarker string `xml:"NextMarker"` // The marker filter for the next list call
  17. Owner Owner `xml:"Owner"` // The owner information
  18. Buckets []BucketProperties `xml:"Buckets>Bucket"` // The bucket list
  19. }
  20. // BucketProperties defines bucket properties
  21. type BucketProperties struct {
  22. XMLName xml.Name `xml:"Bucket"`
  23. Name string `xml:"Name"` // Bucket name
  24. Location string `xml:"Location"` // Bucket datacenter
  25. CreationDate time.Time `xml:"CreationDate"` // Bucket create time
  26. StorageClass string `xml:"StorageClass"` // Bucket storage class
  27. }
  28. // GetBucketACLResult defines GetBucketACL request's result
  29. type GetBucketACLResult struct {
  30. XMLName xml.Name `xml:"AccessControlPolicy"`
  31. ACL string `xml:"AccessControlList>Grant"` // Bucket ACL
  32. Owner Owner `xml:"Owner"` // Bucket owner
  33. }
  34. // LifecycleConfiguration is the Bucket Lifecycle configuration
  35. type LifecycleConfiguration struct {
  36. XMLName xml.Name `xml:"LifecycleConfiguration"`
  37. Rules []LifecycleRule `xml:"Rule"`
  38. }
  39. // LifecycleRule defines Lifecycle rules
  40. type LifecycleRule struct {
  41. XMLName xml.Name `xml:"Rule"`
  42. ID string `xml:"ID,omitempty"` // The rule ID
  43. Prefix string `xml:"Prefix"` // The object key prefix
  44. Status string `xml:"Status"` // The rule status (enabled or not)
  45. Tags []Tag `xml:"Tag,omitempty"` // the tags property
  46. Expiration *LifecycleExpiration `xml:"Expiration,omitempty"` // The expiration property
  47. Transitions []LifecycleTransition `xml:"Transition,omitempty"` // The transition property
  48. AbortMultipartUpload *LifecycleAbortMultipartUpload `xml:"AbortMultipartUpload,omitempty"` // The AbortMultipartUpload property
  49. NonVersionExpiration *LifecycleVersionExpiration `xml:"NoncurrentVersionExpiration,omitempty"`
  50. NonVersionTransition *LifecycleVersionTransition `xml:"NoncurrentVersionTransition,omitempty"`
  51. }
  52. // LifecycleExpiration defines the rule's expiration property
  53. type LifecycleExpiration struct {
  54. XMLName xml.Name `xml:"Expiration"`
  55. Days int `xml:"Days,omitempty"` // Relative expiration time: The expiration time in days after the last modified time
  56. Date string `xml:"Date,omitempty"` // Absolute expiration time: The expiration time in date, not recommended
  57. CreatedBeforeDate string `xml:"CreatedBeforeDate,omitempty"` // objects created before the date will be expired
  58. ExpiredObjectDeleteMarker *bool `xml:"ExpiredObjectDeleteMarker,omitempty"` // Specifies whether the expired delete tag is automatically deleted
  59. }
  60. // LifecycleTransition defines the rule's transition propery
  61. type LifecycleTransition struct {
  62. XMLName xml.Name `xml:"Transition"`
  63. Days int `xml:"Days,omitempty"` // Relative transition time: The transition time in days after the last modified time
  64. CreatedBeforeDate string `xml:"CreatedBeforeDate,omitempty"` // objects created before the date will be expired
  65. StorageClass StorageClassType `xml:"StorageClass,omitempty"` // Specifies the target storage type
  66. }
  67. // LifecycleAbortMultipartUpload defines the rule's abort multipart upload propery
  68. type LifecycleAbortMultipartUpload struct {
  69. XMLName xml.Name `xml:"AbortMultipartUpload"`
  70. Days int `xml:"Days,omitempty"` // Relative expiration time: The expiration time in days after the last modified time
  71. CreatedBeforeDate string `xml:"CreatedBeforeDate,omitempty"` // objects created before the date will be expired
  72. }
  73. // LifecycleVersionExpiration defines the rule's NoncurrentVersionExpiration propery
  74. type LifecycleVersionExpiration struct {
  75. XMLName xml.Name `xml:"NoncurrentVersionExpiration"`
  76. NoncurrentDays int `xml:"NoncurrentDays,omitempty"` // How many days after the Object becomes a non-current version
  77. }
  78. // LifecycleVersionTransition defines the rule's NoncurrentVersionTransition propery
  79. type LifecycleVersionTransition struct {
  80. XMLName xml.Name `xml:"NoncurrentVersionTransition"`
  81. NoncurrentDays int `xml:"NoncurrentDays,omitempty"` // How many days after the Object becomes a non-current version
  82. StorageClass StorageClassType `xml:"StorageClass,omitempty"`
  83. }
  84. const iso8601DateFormat = "2006-01-02T15:04:05.000Z"
  85. // BuildLifecycleRuleByDays builds a lifecycle rule objects will expiration in days after the last modified time
  86. func BuildLifecycleRuleByDays(id, prefix string, status bool, days int) LifecycleRule {
  87. var statusStr = "Enabled"
  88. if !status {
  89. statusStr = "Disabled"
  90. }
  91. return LifecycleRule{ID: id, Prefix: prefix, Status: statusStr,
  92. Expiration: &LifecycleExpiration{Days: days}}
  93. }
  94. // BuildLifecycleRuleByDate builds a lifecycle rule objects will expiration in specified date
  95. func BuildLifecycleRuleByDate(id, prefix string, status bool, year, month, day int) LifecycleRule {
  96. var statusStr = "Enabled"
  97. if !status {
  98. statusStr = "Disabled"
  99. }
  100. date := time.Date(year, time.Month(month), day, 0, 0, 0, 0, time.UTC).Format(iso8601DateFormat)
  101. return LifecycleRule{ID: id, Prefix: prefix, Status: statusStr,
  102. Expiration: &LifecycleExpiration{Date: date}}
  103. }
  104. // ValidateLifecycleRule Determine if a lifecycle rule is valid, if it is invalid, it will return an error.
  105. func verifyLifecycleRules(rules []LifecycleRule) error {
  106. if len(rules) == 0 {
  107. return fmt.Errorf("invalid rules, the length of rules is zero")
  108. }
  109. for _, rule := range rules {
  110. if rule.Status != "Enabled" && rule.Status != "Disabled" {
  111. return fmt.Errorf("invalid rule, the value of status must be Enabled or Disabled")
  112. }
  113. abortMPU := rule.AbortMultipartUpload
  114. if abortMPU != nil {
  115. if (abortMPU.Days != 0 && abortMPU.CreatedBeforeDate != "") || (abortMPU.Days == 0 && abortMPU.CreatedBeforeDate == "") {
  116. return fmt.Errorf("invalid abort multipart upload lifecycle, must be set one of CreatedBeforeDate and Days")
  117. }
  118. }
  119. transitions := rule.Transitions
  120. if len(transitions) > 0 {
  121. if len(transitions) > 2 {
  122. return fmt.Errorf("invalid count of transition lifecycles, the count must than less than 3")
  123. }
  124. for _, transition := range transitions {
  125. if (transition.Days != 0 && transition.CreatedBeforeDate != "") || (transition.Days == 0 && transition.CreatedBeforeDate == "") {
  126. return fmt.Errorf("invalid transition lifecycle, must be set one of CreatedBeforeDate and Days")
  127. }
  128. if transition.StorageClass != StorageIA && transition.StorageClass != StorageArchive {
  129. return fmt.Errorf("invalid transition lifecylce, the value of storage class must be IA or Archive")
  130. }
  131. }
  132. } else if rule.Expiration == nil && abortMPU == nil && rule.NonVersionExpiration == nil && rule.NonVersionTransition == nil {
  133. return fmt.Errorf("invalid rule, must set one of Expiration, AbortMultipartUplaod, NonVersionExpiration, NonVersionTransition and Transitions")
  134. }
  135. }
  136. return nil
  137. }
  138. // GetBucketLifecycleResult defines GetBucketLifecycle's result object
  139. type GetBucketLifecycleResult LifecycleConfiguration
  140. // RefererXML defines Referer configuration
  141. type RefererXML struct {
  142. XMLName xml.Name `xml:"RefererConfiguration"`
  143. AllowEmptyReferer bool `xml:"AllowEmptyReferer"` // Allow empty referrer
  144. RefererList []string `xml:"RefererList>Referer"` // Referer whitelist
  145. }
  146. // GetBucketRefererResult defines result object for GetBucketReferer request
  147. type GetBucketRefererResult RefererXML
  148. // LoggingXML defines logging configuration
  149. type LoggingXML struct {
  150. XMLName xml.Name `xml:"BucketLoggingStatus"`
  151. LoggingEnabled LoggingEnabled `xml:"LoggingEnabled"` // The logging configuration information
  152. }
  153. type loggingXMLEmpty struct {
  154. XMLName xml.Name `xml:"BucketLoggingStatus"`
  155. }
  156. // LoggingEnabled defines the logging configuration information
  157. type LoggingEnabled struct {
  158. XMLName xml.Name `xml:"LoggingEnabled"`
  159. TargetBucket string `xml:"TargetBucket"` // The bucket name for storing the log files
  160. TargetPrefix string `xml:"TargetPrefix"` // The log file prefix
  161. }
  162. // GetBucketLoggingResult defines the result from GetBucketLogging request
  163. type GetBucketLoggingResult LoggingXML
  164. // WebsiteXML defines Website configuration
  165. type WebsiteXML struct {
  166. XMLName xml.Name `xml:"WebsiteConfiguration"`
  167. IndexDocument IndexDocument `xml:"IndexDocument,omitempty"` // The index page
  168. ErrorDocument ErrorDocument `xml:"ErrorDocument,omitempty"` // The error page
  169. RoutingRules []RoutingRule `xml:"RoutingRules>RoutingRule,omitempty"` // The routing Rule list
  170. }
  171. // IndexDocument defines the index page info
  172. type IndexDocument struct {
  173. XMLName xml.Name `xml:"IndexDocument"`
  174. Suffix string `xml:"Suffix"` // The file name for the index page
  175. }
  176. // ErrorDocument defines the 404 error page info
  177. type ErrorDocument struct {
  178. XMLName xml.Name `xml:"ErrorDocument"`
  179. Key string `xml:"Key"` // 404 error file name
  180. }
  181. // RoutingRule defines the routing rules
  182. type RoutingRule struct {
  183. XMLName xml.Name `xml:"RoutingRule"`
  184. RuleNumber int `xml:"RuleNumber,omitempty"` // The routing number
  185. Condition Condition `xml:"Condition,omitempty"` // The routing condition
  186. Redirect Redirect `xml:"Redirect,omitempty"` // The routing redirect
  187. }
  188. // Condition defines codition in the RoutingRule
  189. type Condition struct {
  190. XMLName xml.Name `xml:"Condition"`
  191. KeyPrefixEquals string `xml:"KeyPrefixEquals,omitempty"` // Matching objcet prefix
  192. HTTPErrorCodeReturnedEquals int `xml:"HttpErrorCodeReturnedEquals,omitempty"` // The rule is for Accessing to the specified object
  193. IncludeHeader []IncludeHeader `xml:"IncludeHeader"` // The rule is for request which include header
  194. }
  195. // IncludeHeader defines includeHeader in the RoutingRule's Condition
  196. type IncludeHeader struct {
  197. XMLName xml.Name `xml:"IncludeHeader"`
  198. Key string `xml:"Key,omitempty"` // The Include header key
  199. Equals string `xml:"Equals,omitempty"` // The Include header value
  200. }
  201. // Redirect defines redirect in the RoutingRule
  202. type Redirect struct {
  203. XMLName xml.Name `xml:"Redirect"`
  204. RedirectType string `xml:"RedirectType,omitempty"` // The redirect type, it have Mirror,External,Internal,AliCDN
  205. PassQueryString *bool `xml:"PassQueryString"` // Whether to send the specified request's parameters, true or false
  206. MirrorURL string `xml:"MirrorURL,omitempty"` // Mirror of the website address back to the source.
  207. MirrorPassQueryString *bool `xml:"MirrorPassQueryString"` // To Mirror of the website Whether to send the specified request's parameters, true or false
  208. MirrorFollowRedirect *bool `xml:"MirrorFollowRedirect"` // Redirect the location, if the mirror return 3XX
  209. MirrorCheckMd5 *bool `xml:"MirrorCheckMd5"` // Check the mirror is MD5.
  210. MirrorHeaders MirrorHeaders `xml:"MirrorHeaders,omitempty"` // Mirror headers
  211. Protocol string `xml:"Protocol,omitempty"` // The redirect Protocol
  212. HostName string `xml:"HostName,omitempty"` // The redirect HostName
  213. ReplaceKeyPrefixWith string `xml:"ReplaceKeyPrefixWith,omitempty"` // object name'Prefix replace the value
  214. HttpRedirectCode int `xml:"HttpRedirectCode,omitempty"` // THe redirect http code
  215. ReplaceKeyWith string `xml:"ReplaceKeyWith,omitempty"` // object name replace the value
  216. }
  217. // MirrorHeaders defines MirrorHeaders in the Redirect
  218. type MirrorHeaders struct {
  219. XMLName xml.Name `xml:"MirrorHeaders"`
  220. PassAll *bool `xml:"PassAll"` // Penetrating all of headers to source website.
  221. Pass []string `xml:"Pass"` // Penetrating some of headers to source website.
  222. Remove []string `xml:"Remove"` // Prohibit passthrough some of headers to source website
  223. Set []MirrorHeaderSet `xml:"Set"` // Setting some of headers send to source website
  224. }
  225. // MirrorHeaderSet defines Set for Redirect's MirrorHeaders
  226. type MirrorHeaderSet struct {
  227. XMLName xml.Name `xml:"Set"`
  228. Key string `xml:"Key,omitempty"` // The mirror header key
  229. Value string `xml:"Value,omitempty"` // The mirror header value
  230. }
  231. // GetBucketWebsiteResult defines the result from GetBucketWebsite request.
  232. type GetBucketWebsiteResult WebsiteXML
  233. // CORSXML defines CORS configuration
  234. type CORSXML struct {
  235. XMLName xml.Name `xml:"CORSConfiguration"`
  236. CORSRules []CORSRule `xml:"CORSRule"` // CORS rules
  237. }
  238. // CORSRule defines CORS rules
  239. type CORSRule struct {
  240. XMLName xml.Name `xml:"CORSRule"`
  241. AllowedOrigin []string `xml:"AllowedOrigin"` // Allowed origins. By default it's wildcard '*'
  242. AllowedMethod []string `xml:"AllowedMethod"` // Allowed methods
  243. AllowedHeader []string `xml:"AllowedHeader"` // Allowed headers
  244. ExposeHeader []string `xml:"ExposeHeader"` // Allowed response headers
  245. MaxAgeSeconds int `xml:"MaxAgeSeconds"` // Max cache ages in seconds
  246. }
  247. // GetBucketCORSResult defines the result from GetBucketCORS request.
  248. type GetBucketCORSResult CORSXML
  249. // GetBucketInfoResult defines the result from GetBucketInfo request.
  250. type GetBucketInfoResult struct {
  251. XMLName xml.Name `xml:"BucketInfo"`
  252. BucketInfo BucketInfo `xml:"Bucket"`
  253. }
  254. // BucketInfo defines Bucket information
  255. type BucketInfo struct {
  256. XMLName xml.Name `xml:"Bucket"`
  257. Name string `xml:"Name"` // Bucket name
  258. Location string `xml:"Location"` // Bucket datacenter
  259. CreationDate time.Time `xml:"CreationDate"` // Bucket creation time
  260. ExtranetEndpoint string `xml:"ExtranetEndpoint"` // Bucket external endpoint
  261. IntranetEndpoint string `xml:"IntranetEndpoint"` // Bucket internal endpoint
  262. ACL string `xml:"AccessControlList>Grant"` // Bucket ACL
  263. RedundancyType string `xml:"DataRedundancyType"` // Bucket DataRedundancyType
  264. Owner Owner `xml:"Owner"` // Bucket owner
  265. StorageClass string `xml:"StorageClass"` // Bucket storage class
  266. SseRule SSERule `xml:"ServerSideEncryptionRule"` // Bucket ServerSideEncryptionRule
  267. Versioning string `xml:"Versioning"` // Bucket Versioning
  268. }
  269. type SSERule struct {
  270. XMLName xml.Name `xml:"ServerSideEncryptionRule"` // Bucket ServerSideEncryptionRule
  271. KMSMasterKeyID string `xml:"KMSMasterKeyID"` // Bucket KMSMasterKeyID
  272. SSEAlgorithm string `xml:"SSEAlgorithm"` // Bucket SSEAlgorithm
  273. }
  274. // ListObjectsResult defines the result from ListObjects request
  275. type ListObjectsResult struct {
  276. XMLName xml.Name `xml:"ListBucketResult"`
  277. Prefix string `xml:"Prefix"` // The object prefix
  278. Marker string `xml:"Marker"` // The marker filter.
  279. MaxKeys int `xml:"MaxKeys"` // Max keys to return
  280. Delimiter string `xml:"Delimiter"` // The delimiter for grouping objects' name
  281. IsTruncated bool `xml:"IsTruncated"` // Flag indicates if all results are returned (when it's false)
  282. NextMarker string `xml:"NextMarker"` // The start point of the next query
  283. Objects []ObjectProperties `xml:"Contents"` // Object list
  284. CommonPrefixes []string `xml:"CommonPrefixes>Prefix"` // You can think of commonprefixes as "folders" whose names end with the delimiter
  285. }
  286. // ObjectProperties defines Objecct properties
  287. type ObjectProperties struct {
  288. XMLName xml.Name `xml:"Contents"`
  289. Key string `xml:"Key"` // Object key
  290. Type string `xml:"Type"` // Object type
  291. Size int64 `xml:"Size"` // Object size
  292. ETag string `xml:"ETag"` // Object ETag
  293. Owner Owner `xml:"Owner"` // Object owner information
  294. LastModified time.Time `xml:"LastModified"` // Object last modified time
  295. StorageClass string `xml:"StorageClass"` // Object storage class (Standard, IA, Archive)
  296. }
  297. // ListObjectVersionsResult defines the result from ListObjectVersions request
  298. type ListObjectVersionsResult struct {
  299. XMLName xml.Name `xml:"ListVersionsResult"`
  300. Name string `xml:"Name"` // The Bucket Name
  301. Owner Owner `xml:"Owner"` // The owner of bucket
  302. Prefix string `xml:"Prefix"` // The object prefix
  303. KeyMarker string `xml:"KeyMarker"` // The start marker filter.
  304. VersionIdMarker string `xml:"VersionIdMarker"` // The start VersionIdMarker filter.
  305. MaxKeys int `xml:"MaxKeys"` // Max keys to return
  306. Delimiter string `xml:"Delimiter"` // The delimiter for grouping objects' name
  307. IsTruncated bool `xml:"IsTruncated"` // Flag indicates if all results are returned (when it's false)
  308. NextKeyMarker string `xml:"NextKeyMarker"` // The start point of the next query
  309. NextVersionIdMarker string `xml:"NextVersionIdMarker"` // The start point of the next query
  310. CommonPrefixes []string `xml:"CommonPrefixes>Prefix"` // You can think of commonprefixes as "folders" whose names end with the delimiter
  311. ObjectDeleteMarkers []ObjectDeleteMarkerProperties `xml:"DeleteMarker"` // DeleteMarker list
  312. ObjectVersions []ObjectVersionProperties `xml:"Version"` // version list
  313. }
  314. type ObjectDeleteMarkerProperties struct {
  315. XMLName xml.Name `xml:"DeleteMarker"`
  316. Key string `xml:"Key"` // The Object Key
  317. VersionId string `xml:"VersionId"` // The Object VersionId
  318. IsLatest bool `xml:"IsLatest"` // is current version or not
  319. LastModified time.Time `xml:"LastModified"` // Object last modified time
  320. Owner Owner `xml:"Owner"` // bucket owner element
  321. }
  322. type ObjectVersionProperties struct {
  323. XMLName xml.Name `xml:"Version"`
  324. Key string `xml:"Key"` // The Object Key
  325. VersionId string `xml:"VersionId"` // The Object VersionId
  326. IsLatest bool `xml:"IsLatest"` // is latest version or not
  327. LastModified time.Time `xml:"LastModified"` // Object last modified time
  328. Type string `xml:"Type"` // Object type
  329. Size int64 `xml:"Size"` // Object size
  330. ETag string `xml:"ETag"` // Object ETag
  331. StorageClass string `xml:"StorageClass"` // Object storage class (Standard, IA, Archive)
  332. Owner Owner `xml:"Owner"` // bucket owner element
  333. }
  334. // Owner defines Bucket/Object's owner
  335. type Owner struct {
  336. XMLName xml.Name `xml:"Owner"`
  337. ID string `xml:"ID"` // Owner ID
  338. DisplayName string `xml:"DisplayName"` // Owner's display name
  339. }
  340. // CopyObjectResult defines result object of CopyObject
  341. type CopyObjectResult struct {
  342. XMLName xml.Name `xml:"CopyObjectResult"`
  343. LastModified time.Time `xml:"LastModified"` // New object's last modified time.
  344. ETag string `xml:"ETag"` // New object's ETag
  345. }
  346. // GetObjectACLResult defines result of GetObjectACL request
  347. type GetObjectACLResult GetBucketACLResult
  348. type deleteXML struct {
  349. XMLName xml.Name `xml:"Delete"`
  350. Objects []DeleteObject `xml:"Object"` // Objects to delete
  351. Quiet bool `xml:"Quiet"` // Flag of quiet mode.
  352. }
  353. // DeleteObject defines the struct for deleting object
  354. type DeleteObject struct {
  355. XMLName xml.Name `xml:"Object"`
  356. Key string `xml:"Key"` // Object name
  357. VersionId string `xml:"VersionId,omitempty"` // Object VersionId
  358. }
  359. // DeleteObjectsResult defines result of DeleteObjects request
  360. type DeleteObjectsResult struct {
  361. XMLName xml.Name
  362. DeletedObjects []string // Deleted object key list
  363. }
  364. // DeleteObjectsResult_inner defines result of DeleteObjects request
  365. type DeleteObjectVersionsResult struct {
  366. XMLName xml.Name `xml:"DeleteResult"`
  367. DeletedObjectsDetail []DeletedKeyInfo `xml:"Deleted"` // Deleted object detail info
  368. }
  369. // DeleteKeyInfo defines object delete info
  370. type DeletedKeyInfo struct {
  371. XMLName xml.Name `xml:"Deleted"`
  372. Key string `xml:"Key"` // Object key
  373. VersionId string `xml:"VersionId"` // VersionId
  374. DeleteMarker bool `xml:"DeleteMarker"` // Object DeleteMarker
  375. DeleteMarkerVersionId string `xml:"DeleteMarkerVersionId"` // Object DeleteMarkerVersionId
  376. }
  377. // InitiateMultipartUploadResult defines result of InitiateMultipartUpload request
  378. type InitiateMultipartUploadResult struct {
  379. XMLName xml.Name `xml:"InitiateMultipartUploadResult"`
  380. Bucket string `xml:"Bucket"` // Bucket name
  381. Key string `xml:"Key"` // Object name to upload
  382. UploadID string `xml:"UploadId"` // Generated UploadId
  383. }
  384. // UploadPart defines the upload/copy part
  385. type UploadPart struct {
  386. XMLName xml.Name `xml:"Part"`
  387. PartNumber int `xml:"PartNumber"` // Part number
  388. ETag string `xml:"ETag"` // ETag value of the part's data
  389. }
  390. type uploadParts []UploadPart
  391. func (slice uploadParts) Len() int {
  392. return len(slice)
  393. }
  394. func (slice uploadParts) Less(i, j int) bool {
  395. return slice[i].PartNumber < slice[j].PartNumber
  396. }
  397. func (slice uploadParts) Swap(i, j int) {
  398. slice[i], slice[j] = slice[j], slice[i]
  399. }
  400. // UploadPartCopyResult defines result object of multipart copy request.
  401. type UploadPartCopyResult struct {
  402. XMLName xml.Name `xml:"CopyPartResult"`
  403. LastModified time.Time `xml:"LastModified"` // Last modified time
  404. ETag string `xml:"ETag"` // ETag
  405. }
  406. type completeMultipartUploadXML struct {
  407. XMLName xml.Name `xml:"CompleteMultipartUpload"`
  408. Part []UploadPart `xml:"Part"`
  409. }
  410. // CompleteMultipartUploadResult defines result object of CompleteMultipartUploadRequest
  411. type CompleteMultipartUploadResult struct {
  412. XMLName xml.Name `xml:"CompleteMultipartUploadResult"`
  413. Location string `xml:"Location"` // Object URL
  414. Bucket string `xml:"Bucket"` // Bucket name
  415. ETag string `xml:"ETag"` // Object ETag
  416. Key string `xml:"Key"` // Object name
  417. }
  418. // ListUploadedPartsResult defines result object of ListUploadedParts
  419. type ListUploadedPartsResult struct {
  420. XMLName xml.Name `xml:"ListPartsResult"`
  421. Bucket string `xml:"Bucket"` // Bucket name
  422. Key string `xml:"Key"` // Object name
  423. UploadID string `xml:"UploadId"` // Upload ID
  424. NextPartNumberMarker string `xml:"NextPartNumberMarker"` // Next part number
  425. MaxParts int `xml:"MaxParts"` // Max parts count
  426. IsTruncated bool `xml:"IsTruncated"` // Flag indicates all entries returned.false: all entries returned.
  427. UploadedParts []UploadedPart `xml:"Part"` // Uploaded parts
  428. }
  429. // UploadedPart defines uploaded part
  430. type UploadedPart struct {
  431. XMLName xml.Name `xml:"Part"`
  432. PartNumber int `xml:"PartNumber"` // Part number
  433. LastModified time.Time `xml:"LastModified"` // Last modified time
  434. ETag string `xml:"ETag"` // ETag cache
  435. Size int `xml:"Size"` // Part size
  436. }
  437. // ListMultipartUploadResult defines result object of ListMultipartUpload
  438. type ListMultipartUploadResult struct {
  439. XMLName xml.Name `xml:"ListMultipartUploadsResult"`
  440. Bucket string `xml:"Bucket"` // Bucket name
  441. Delimiter string `xml:"Delimiter"` // Delimiter for grouping object.
  442. Prefix string `xml:"Prefix"` // Object prefix
  443. KeyMarker string `xml:"KeyMarker"` // Object key marker
  444. UploadIDMarker string `xml:"UploadIdMarker"` // UploadId marker
  445. NextKeyMarker string `xml:"NextKeyMarker"` // Next key marker, if not all entries returned.
  446. NextUploadIDMarker string `xml:"NextUploadIdMarker"` // Next uploadId marker, if not all entries returned.
  447. MaxUploads int `xml:"MaxUploads"` // Max uploads to return
  448. IsTruncated bool `xml:"IsTruncated"` // Flag indicates all entries are returned.
  449. Uploads []UncompletedUpload `xml:"Upload"` // Ongoing uploads (not completed, not aborted)
  450. CommonPrefixes []string `xml:"CommonPrefixes>Prefix"` // Common prefixes list.
  451. }
  452. // UncompletedUpload structure wraps an uncompleted upload task
  453. type UncompletedUpload struct {
  454. XMLName xml.Name `xml:"Upload"`
  455. Key string `xml:"Key"` // Object name
  456. UploadID string `xml:"UploadId"` // The UploadId
  457. Initiated time.Time `xml:"Initiated"` // Initialization time in the format such as 2012-02-23T04:18:23.000Z
  458. }
  459. // ProcessObjectResult defines result object of ProcessObject
  460. type ProcessObjectResult struct {
  461. Bucket string `json:"bucket"`
  462. FileSize int `json:"fileSize"`
  463. Object string `json:"object"`
  464. Status string `json:"status"`
  465. }
  466. // decodeDeleteObjectsResult decodes deleting objects result in URL encoding
  467. func decodeDeleteObjectsResult(result *DeleteObjectVersionsResult) error {
  468. var err error
  469. for i := 0; i < len(result.DeletedObjectsDetail); i++ {
  470. result.DeletedObjectsDetail[i].Key, err = url.QueryUnescape(result.DeletedObjectsDetail[i].Key)
  471. if err != nil {
  472. return err
  473. }
  474. }
  475. return nil
  476. }
  477. // decodeListObjectsResult decodes list objects result in URL encoding
  478. func decodeListObjectsResult(result *ListObjectsResult) error {
  479. var err error
  480. result.Prefix, err = url.QueryUnescape(result.Prefix)
  481. if err != nil {
  482. return err
  483. }
  484. result.Marker, err = url.QueryUnescape(result.Marker)
  485. if err != nil {
  486. return err
  487. }
  488. result.Delimiter, err = url.QueryUnescape(result.Delimiter)
  489. if err != nil {
  490. return err
  491. }
  492. result.NextMarker, err = url.QueryUnescape(result.NextMarker)
  493. if err != nil {
  494. return err
  495. }
  496. for i := 0; i < len(result.Objects); i++ {
  497. result.Objects[i].Key, err = url.QueryUnescape(result.Objects[i].Key)
  498. if err != nil {
  499. return err
  500. }
  501. }
  502. for i := 0; i < len(result.CommonPrefixes); i++ {
  503. result.CommonPrefixes[i], err = url.QueryUnescape(result.CommonPrefixes[i])
  504. if err != nil {
  505. return err
  506. }
  507. }
  508. return nil
  509. }
  510. // decodeListObjectVersionsResult decodes list version objects result in URL encoding
  511. func decodeListObjectVersionsResult(result *ListObjectVersionsResult) error {
  512. var err error
  513. // decode:Delimiter
  514. result.Delimiter, err = url.QueryUnescape(result.Delimiter)
  515. if err != nil {
  516. return err
  517. }
  518. // decode Prefix
  519. result.Prefix, err = url.QueryUnescape(result.Prefix)
  520. if err != nil {
  521. return err
  522. }
  523. // decode KeyMarker
  524. result.KeyMarker, err = url.QueryUnescape(result.KeyMarker)
  525. if err != nil {
  526. return err
  527. }
  528. // decode VersionIdMarker
  529. result.VersionIdMarker, err = url.QueryUnescape(result.VersionIdMarker)
  530. if err != nil {
  531. return err
  532. }
  533. // decode NextKeyMarker
  534. result.NextKeyMarker, err = url.QueryUnescape(result.NextKeyMarker)
  535. if err != nil {
  536. return err
  537. }
  538. // decode NextVersionIdMarker
  539. result.NextVersionIdMarker, err = url.QueryUnescape(result.NextVersionIdMarker)
  540. if err != nil {
  541. return err
  542. }
  543. // decode CommonPrefixes
  544. for i := 0; i < len(result.CommonPrefixes); i++ {
  545. result.CommonPrefixes[i], err = url.QueryUnescape(result.CommonPrefixes[i])
  546. if err != nil {
  547. return err
  548. }
  549. }
  550. // decode deleteMarker
  551. for i := 0; i < len(result.ObjectDeleteMarkers); i++ {
  552. result.ObjectDeleteMarkers[i].Key, err = url.QueryUnescape(result.ObjectDeleteMarkers[i].Key)
  553. if err != nil {
  554. return err
  555. }
  556. }
  557. // decode ObjectVersions
  558. for i := 0; i < len(result.ObjectVersions); i++ {
  559. result.ObjectVersions[i].Key, err = url.QueryUnescape(result.ObjectVersions[i].Key)
  560. if err != nil {
  561. return err
  562. }
  563. }
  564. return nil
  565. }
  566. // decodeListUploadedPartsResult decodes
  567. func decodeListUploadedPartsResult(result *ListUploadedPartsResult) error {
  568. var err error
  569. result.Key, err = url.QueryUnescape(result.Key)
  570. if err != nil {
  571. return err
  572. }
  573. return nil
  574. }
  575. // decodeListMultipartUploadResult decodes list multipart upload result in URL encoding
  576. func decodeListMultipartUploadResult(result *ListMultipartUploadResult) error {
  577. var err error
  578. result.Prefix, err = url.QueryUnescape(result.Prefix)
  579. if err != nil {
  580. return err
  581. }
  582. result.Delimiter, err = url.QueryUnescape(result.Delimiter)
  583. if err != nil {
  584. return err
  585. }
  586. result.KeyMarker, err = url.QueryUnescape(result.KeyMarker)
  587. if err != nil {
  588. return err
  589. }
  590. result.NextKeyMarker, err = url.QueryUnescape(result.NextKeyMarker)
  591. if err != nil {
  592. return err
  593. }
  594. for i := 0; i < len(result.Uploads); i++ {
  595. result.Uploads[i].Key, err = url.QueryUnescape(result.Uploads[i].Key)
  596. if err != nil {
  597. return err
  598. }
  599. }
  600. for i := 0; i < len(result.CommonPrefixes); i++ {
  601. result.CommonPrefixes[i], err = url.QueryUnescape(result.CommonPrefixes[i])
  602. if err != nil {
  603. return err
  604. }
  605. }
  606. return nil
  607. }
  608. // createBucketConfiguration defines the configuration for creating a bucket.
  609. type createBucketConfiguration struct {
  610. XMLName xml.Name `xml:"CreateBucketConfiguration"`
  611. StorageClass StorageClassType `xml:"StorageClass,omitempty"`
  612. DataRedundancyType DataRedundancyType `xml:"DataRedundancyType,omitempty"`
  613. }
  614. // LiveChannelConfiguration defines the configuration for live-channel
  615. type LiveChannelConfiguration struct {
  616. XMLName xml.Name `xml:"LiveChannelConfiguration"`
  617. Description string `xml:"Description,omitempty"` //Description of live-channel, up to 128 bytes
  618. Status string `xml:"Status,omitempty"` //Specify the status of livechannel
  619. Target LiveChannelTarget `xml:"Target"` //target configuration of live-channel
  620. // use point instead of struct to avoid omit empty snapshot
  621. Snapshot *LiveChannelSnapshot `xml:"Snapshot,omitempty"` //snapshot configuration of live-channel
  622. }
  623. // LiveChannelTarget target configuration of live-channel
  624. type LiveChannelTarget struct {
  625. XMLName xml.Name `xml:"Target"`
  626. Type string `xml:"Type"` //the type of object, only supports HLS
  627. FragDuration int `xml:"FragDuration,omitempty"` //the length of each ts object (in seconds), in the range [1,100]
  628. FragCount int `xml:"FragCount,omitempty"` //the number of ts objects in the m3u8 object, in the range of [1,100]
  629. PlaylistName string `xml:"PlaylistName,omitempty"` //the name of m3u8 object, which must end with ".m3u8" and the length range is [6,128]
  630. }
  631. // LiveChannelSnapshot snapshot configuration of live-channel
  632. type LiveChannelSnapshot struct {
  633. XMLName xml.Name `xml:"Snapshot"`
  634. RoleName string `xml:"RoleName,omitempty"` //The role of snapshot operations, it sholud has write permission of DestBucket and the permission to send messages to the NotifyTopic.
  635. DestBucket string `xml:"DestBucket,omitempty"` //Bucket the snapshots will be written to. should be the same owner as the source bucket.
  636. NotifyTopic string `xml:"NotifyTopic,omitempty"` //Topics of MNS for notifying users of high frequency screenshot operation results
  637. Interval int `xml:"Interval,omitempty"` //interval of snapshots, threre is no snapshot if no I-frame during the interval time
  638. }
  639. // CreateLiveChannelResult the result of crete live-channel
  640. type CreateLiveChannelResult struct {
  641. XMLName xml.Name `xml:"CreateLiveChannelResult"`
  642. PublishUrls []string `xml:"PublishUrls>Url"` //push urls list
  643. PlayUrls []string `xml:"PlayUrls>Url"` //play urls list
  644. }
  645. // LiveChannelStat the result of get live-channel state
  646. type LiveChannelStat struct {
  647. XMLName xml.Name `xml:"LiveChannelStat"`
  648. Status string `xml:"Status"` //Current push status of live-channel: Disabled,Live,Idle
  649. ConnectedTime time.Time `xml:"ConnectedTime"` //The time when the client starts pushing, format: ISO8601
  650. RemoteAddr string `xml:"RemoteAddr"` //The ip address of the client
  651. Video LiveChannelVideo `xml:"Video"` //Video stream information
  652. Audio LiveChannelAudio `xml:"Audio"` //Audio stream information
  653. }
  654. // LiveChannelVideo video stream information
  655. type LiveChannelVideo struct {
  656. XMLName xml.Name `xml:"Video"`
  657. Width int `xml:"Width"` //Width (unit: pixels)
  658. Height int `xml:"Height"` //Height (unit: pixels)
  659. FrameRate int `xml:"FrameRate"` //FramRate
  660. Bandwidth int `xml:"Bandwidth"` //Bandwidth (unit: B/s)
  661. }
  662. // LiveChannelAudio audio stream information
  663. type LiveChannelAudio struct {
  664. XMLName xml.Name `xml:"Audio"`
  665. SampleRate int `xml:"SampleRate"` //SampleRate
  666. Bandwidth int `xml:"Bandwidth"` //Bandwidth (unit: B/s)
  667. Codec string `xml:"Codec"` //Encoding forma
  668. }
  669. // LiveChannelHistory the result of GetLiveChannelHistory, at most return up to lastest 10 push records
  670. type LiveChannelHistory struct {
  671. XMLName xml.Name `xml:"LiveChannelHistory"`
  672. Record []LiveRecord `xml:"LiveRecord"` //push records list
  673. }
  674. // LiveRecord push recode
  675. type LiveRecord struct {
  676. XMLName xml.Name `xml:"LiveRecord"`
  677. StartTime time.Time `xml:"StartTime"` //StartTime, format: ISO8601
  678. EndTime time.Time `xml:"EndTime"` //EndTime, format: ISO8601
  679. RemoteAddr string `xml:"RemoteAddr"` //The ip address of remote client
  680. }
  681. // ListLiveChannelResult the result of ListLiveChannel
  682. type ListLiveChannelResult struct {
  683. XMLName xml.Name `xml:"ListLiveChannelResult"`
  684. Prefix string `xml:"Prefix"` //Filter by the name start with the value of "Prefix"
  685. Marker string `xml:"Marker"` //cursor from which starting list
  686. MaxKeys int `xml:"MaxKeys"` //The maximum count returned. the default value is 100. it cannot be greater than 1000.
  687. IsTruncated bool `xml:"IsTruncated"` //Indicates whether all results have been returned, "true" indicates partial results returned while "false" indicates all results have been returned
  688. NextMarker string `xml:"NextMarker"` //NextMarker indicate the Marker value of the next request
  689. LiveChannel []LiveChannelInfo `xml:"LiveChannel"` //The infomation of live-channel
  690. }
  691. // LiveChannelInfo the infomation of live-channel
  692. type LiveChannelInfo struct {
  693. XMLName xml.Name `xml:"LiveChannel"`
  694. Name string `xml:"Name"` //The name of live-channel
  695. Description string `xml:"Description"` //Description of live-channel
  696. Status string `xml:"Status"` //Status: disabled or enabled
  697. LastModified time.Time `xml:"LastModified"` //Last modification time, format: ISO8601
  698. PublishUrls []string `xml:"PublishUrls>Url"` //push urls list
  699. PlayUrls []string `xml:"PlayUrls>Url"` //play urls list
  700. }
  701. // Tag a tag for the object
  702. type Tag struct {
  703. XMLName xml.Name `xml:"Tag"`
  704. Key string `xml:"Key"`
  705. Value string `xml:"Value"`
  706. }
  707. // Tagging tagset for the object
  708. type Tagging struct {
  709. XMLName xml.Name `xml:"Tagging"`
  710. Tags []Tag `xml:"TagSet>Tag,omitempty"`
  711. }
  712. // for GetObjectTagging return value
  713. type GetObjectTaggingResult Tagging
  714. // VersioningConfig for the bucket
  715. type VersioningConfig struct {
  716. XMLName xml.Name `xml:"VersioningConfiguration"`
  717. Status string `xml:"Status"`
  718. }
  719. type GetBucketVersioningResult VersioningConfig
  720. // Server Encryption rule for the bucket
  721. type ServerEncryptionRule struct {
  722. XMLName xml.Name `xml:"ServerSideEncryptionRule"`
  723. SSEDefault SSEDefaultRule `xml:"ApplyServerSideEncryptionByDefault"`
  724. }
  725. // Server Encryption deafult rule for the bucket
  726. type SSEDefaultRule struct {
  727. XMLName xml.Name `xml:"ApplyServerSideEncryptionByDefault"`
  728. SSEAlgorithm string `xml:"SSEAlgorithm"`
  729. KMSMasterKeyID string `xml:"KMSMasterKeyID"`
  730. }
  731. type GetBucketEncryptionResult ServerEncryptionRule
  732. type GetBucketTaggingResult Tagging
  733. type BucketStat struct {
  734. XMLName xml.Name `xml:"BucketStat"`
  735. Storage int64 `xml:"Storage"`
  736. ObjectCount int64 `xml:"ObjectCount"`
  737. MultipartUploadCount int64 `xml:"MultipartUploadCount"`
  738. }
  739. type GetBucketStatResult BucketStat
  740. // RequestPaymentConfiguration define the request payment configuration
  741. type RequestPaymentConfiguration struct {
  742. XMLName xml.Name `xml:"RequestPaymentConfiguration"`
  743. Payer string `xml:"Payer,omitempty"`
  744. }
  745. // BucketQoSConfiguration define QoS configuration
  746. type BucketQoSConfiguration struct {
  747. XMLName xml.Name `xml:"QoSConfiguration"`
  748. TotalUploadBandwidth *int `xml:"TotalUploadBandwidth"` // Total upload bandwidth
  749. IntranetUploadBandwidth *int `xml:"IntranetUploadBandwidth"` // Intranet upload bandwidth
  750. ExtranetUploadBandwidth *int `xml:"ExtranetUploadBandwidth"` // Extranet upload bandwidth
  751. TotalDownloadBandwidth *int `xml:"TotalDownloadBandwidth"` // Total download bandwidth
  752. IntranetDownloadBandwidth *int `xml:"IntranetDownloadBandwidth"` // Intranet download bandwidth
  753. ExtranetDownloadBandwidth *int `xml:"ExtranetDownloadBandwidth"` // Extranet download bandwidth
  754. TotalQPS *int `xml:"TotalQps"` // Total Qps
  755. IntranetQPS *int `xml:"IntranetQps"` // Intranet Qps
  756. ExtranetQPS *int `xml:"ExtranetQps"` // Extranet Qps
  757. }
  758. // UserQoSConfiguration define QoS and Range configuration
  759. type UserQoSConfiguration struct {
  760. XMLName xml.Name `xml:"QoSConfiguration"`
  761. Region string `xml:"Region,omitempty"` // Effective area of Qos configuration
  762. BucketQoSConfiguration
  763. }
  764. //////////////////////////////////////////////////////////////
  765. /////////////////// Select OBject ////////////////////////////
  766. //////////////////////////////////////////////////////////////
  767. type CsvMetaRequest struct {
  768. XMLName xml.Name `xml:"CsvMetaRequest"`
  769. InputSerialization InputSerialization `xml:"InputSerialization"`
  770. OverwriteIfExists *bool `xml:"OverwriteIfExists,omitempty"`
  771. }
  772. // encodeBase64 encode base64 of the CreateSelectObjectMeta api request params
  773. func (meta *CsvMetaRequest) encodeBase64() {
  774. meta.InputSerialization.CSV.RecordDelimiter =
  775. base64.StdEncoding.EncodeToString([]byte(meta.InputSerialization.CSV.RecordDelimiter))
  776. meta.InputSerialization.CSV.FieldDelimiter =
  777. base64.StdEncoding.EncodeToString([]byte(meta.InputSerialization.CSV.FieldDelimiter))
  778. meta.InputSerialization.CSV.QuoteCharacter =
  779. base64.StdEncoding.EncodeToString([]byte(meta.InputSerialization.CSV.QuoteCharacter))
  780. }
  781. type JsonMetaRequest struct {
  782. XMLName xml.Name `xml:"JsonMetaRequest"`
  783. InputSerialization InputSerialization `xml:"InputSerialization"`
  784. OverwriteIfExists *bool `xml:"OverwriteIfExists,omitempty"`
  785. }
  786. type InputSerialization struct {
  787. XMLName xml.Name `xml:"InputSerialization"`
  788. CSV CSV `xml:CSV,omitempty`
  789. JSON JSON `xml:JSON,omitempty`
  790. CompressionType string `xml:"CompressionType,omitempty"`
  791. }
  792. type CSV struct {
  793. XMLName xml.Name `xml:"CSV"`
  794. RecordDelimiter string `xml:"RecordDelimiter,omitempty"`
  795. FieldDelimiter string `xml:"FieldDelimiter,omitempty"`
  796. QuoteCharacter string `xml:"QuoteCharacter,omitempty"`
  797. }
  798. type JSON struct {
  799. XMLName xml.Name `xml:"JSON"`
  800. JSONType string `xml:"Type,omitempty"`
  801. }
  802. // SelectRequest is for the SelectObject request params of json file
  803. type SelectRequest struct {
  804. XMLName xml.Name `xml:"SelectRequest"`
  805. Expression string `xml:"Expression"`
  806. InputSerializationSelect InputSerializationSelect `xml:"InputSerialization"`
  807. OutputSerializationSelect OutputSerializationSelect `xml:"OutputSerialization"`
  808. SelectOptions SelectOptions `xml:"Options,omitempty"`
  809. }
  810. type InputSerializationSelect struct {
  811. XMLName xml.Name `xml:"InputSerialization"`
  812. CsvBodyInput CSVSelectInput `xml:CSV,omitempty`
  813. JsonBodyInput JSONSelectInput `xml:JSON,omitempty`
  814. CompressionType string `xml:"CompressionType,omitempty"`
  815. }
  816. type CSVSelectInput struct {
  817. XMLName xml.Name `xml:"CSV"`
  818. FileHeaderInfo string `xml:"FileHeaderInfo,omitempty"`
  819. RecordDelimiter string `xml:"RecordDelimiter,omitempty"`
  820. FieldDelimiter string `xml:"FieldDelimiter,omitempty"`
  821. QuoteCharacter string `xml:"QuoteCharacter,omitempty"`
  822. CommentCharacter string `xml:"CommentCharacter,omitempty"`
  823. Range string `xml:"Range,omitempty"`
  824. SplitRange string
  825. }
  826. type JSONSelectInput struct {
  827. XMLName xml.Name `xml:"JSON"`
  828. JSONType string `xml:"Type,omitempty"`
  829. Range string `xml:"Range,omitempty"`
  830. ParseJSONNumberAsString *bool `xml:"ParseJsonNumberAsString"`
  831. SplitRange string
  832. }
  833. func (jsonInput *JSONSelectInput) JsonIsEmpty() bool {
  834. if jsonInput.JSONType != "" {
  835. return false
  836. }
  837. return true
  838. }
  839. type OutputSerializationSelect struct {
  840. XMLName xml.Name `xml:"OutputSerialization"`
  841. CsvBodyOutput CSVSelectOutput `xml:CSV,omitempty`
  842. JsonBodyOutput JSONSelectOutput `xml:JSON,omitempty`
  843. OutputRawData *bool `xml:"OutputRawData,omitempty"`
  844. KeepAllColumns *bool `xml:"KeepAllColumns,omitempty"`
  845. EnablePayloadCrc *bool `xml:"EnablePayloadCrc,omitempty"`
  846. OutputHeader *bool `xml:"OutputHeader,omitempty"`
  847. }
  848. type CSVSelectOutput struct {
  849. XMLName xml.Name `xml:"CSV"`
  850. RecordDelimiter string `xml:"RecordDelimiter,omitempty"`
  851. FieldDelimiter string `xml:"FieldDelimiter,omitempty"`
  852. }
  853. type JSONSelectOutput struct {
  854. XMLName xml.Name `xml:"JSON"`
  855. RecordDelimiter string `xml:"RecordDelimiter,omitempty"`
  856. }
  857. func (selectReq *SelectRequest) encodeBase64() {
  858. if selectReq.InputSerializationSelect.JsonBodyInput.JsonIsEmpty() {
  859. selectReq.csvEncodeBase64()
  860. } else {
  861. selectReq.jsonEncodeBase64()
  862. }
  863. }
  864. // csvEncodeBase64 encode base64 of the SelectObject api request params
  865. func (selectReq *SelectRequest) csvEncodeBase64() {
  866. selectReq.Expression = base64.StdEncoding.EncodeToString([]byte(selectReq.Expression))
  867. selectReq.InputSerializationSelect.CsvBodyInput.RecordDelimiter =
  868. base64.StdEncoding.EncodeToString([]byte(selectReq.InputSerializationSelect.CsvBodyInput.RecordDelimiter))
  869. selectReq.InputSerializationSelect.CsvBodyInput.FieldDelimiter =
  870. base64.StdEncoding.EncodeToString([]byte(selectReq.InputSerializationSelect.CsvBodyInput.FieldDelimiter))
  871. selectReq.InputSerializationSelect.CsvBodyInput.QuoteCharacter =
  872. base64.StdEncoding.EncodeToString([]byte(selectReq.InputSerializationSelect.CsvBodyInput.QuoteCharacter))
  873. selectReq.InputSerializationSelect.CsvBodyInput.CommentCharacter =
  874. base64.StdEncoding.EncodeToString([]byte(selectReq.InputSerializationSelect.CsvBodyInput.CommentCharacter))
  875. selectReq.OutputSerializationSelect.CsvBodyOutput.FieldDelimiter =
  876. base64.StdEncoding.EncodeToString([]byte(selectReq.OutputSerializationSelect.CsvBodyOutput.FieldDelimiter))
  877. selectReq.OutputSerializationSelect.CsvBodyOutput.RecordDelimiter =
  878. base64.StdEncoding.EncodeToString([]byte(selectReq.OutputSerializationSelect.CsvBodyOutput.RecordDelimiter))
  879. // handle Range
  880. if selectReq.InputSerializationSelect.CsvBodyInput.Range != "" {
  881. selectReq.InputSerializationSelect.CsvBodyInput.Range = "line-range=" + selectReq.InputSerializationSelect.CsvBodyInput.Range
  882. }
  883. if selectReq.InputSerializationSelect.CsvBodyInput.SplitRange != "" {
  884. selectReq.InputSerializationSelect.CsvBodyInput.Range = "split-range=" + selectReq.InputSerializationSelect.CsvBodyInput.SplitRange
  885. }
  886. }
  887. // jsonEncodeBase64 encode base64 of the SelectObject api request params
  888. func (selectReq *SelectRequest) jsonEncodeBase64() {
  889. selectReq.Expression = base64.StdEncoding.EncodeToString([]byte(selectReq.Expression))
  890. selectReq.OutputSerializationSelect.JsonBodyOutput.RecordDelimiter =
  891. base64.StdEncoding.EncodeToString([]byte(selectReq.OutputSerializationSelect.JsonBodyOutput.RecordDelimiter))
  892. // handle Range
  893. if selectReq.InputSerializationSelect.JsonBodyInput.Range != "" {
  894. selectReq.InputSerializationSelect.JsonBodyInput.Range = "line-range=" + selectReq.InputSerializationSelect.JsonBodyInput.Range
  895. }
  896. if selectReq.InputSerializationSelect.JsonBodyInput.SplitRange != "" {
  897. selectReq.InputSerializationSelect.JsonBodyInput.Range = "split-range=" + selectReq.InputSerializationSelect.JsonBodyInput.SplitRange
  898. }
  899. }
  900. // CsvOptions is a element in the SelectObject api request's params
  901. type SelectOptions struct {
  902. XMLName xml.Name `xml:"Options"`
  903. SkipPartialDataRecord *bool `xml:"SkipPartialDataRecord,omitempty"`
  904. MaxSkippedRecordsAllowed string `xml:"MaxSkippedRecordsAllowed,omitempty"`
  905. }
  906. // SelectObjectResult is the SelectObject api's return
  907. type SelectObjectResult struct {
  908. Version byte
  909. FrameType int32
  910. PayloadLength int32
  911. HeaderCheckSum uint32
  912. Offset uint64
  913. Data string // DataFrame
  914. EndFrame EndFrame // EndFrame
  915. MetaEndFrameCSV MetaEndFrameCSV // MetaEndFrameCSV
  916. MetaEndFrameJSON MetaEndFrameJSON // MetaEndFrameJSON
  917. PayloadChecksum uint32
  918. ReadFlagInfo
  919. }
  920. // ReadFlagInfo if reading the frame data, recode the reading status
  921. type ReadFlagInfo struct {
  922. OpenLine bool
  923. ConsumedBytesLength int32
  924. EnablePayloadCrc bool
  925. OutputRawData bool
  926. }
  927. // EndFrame is EndFrameType of SelectObject api
  928. type EndFrame struct {
  929. TotalScanned int64
  930. HTTPStatusCode int32
  931. ErrorMsg string
  932. }
  933. // MetaEndFrameCSV is MetaEndFrameCSVType of CreateSelectObjectMeta
  934. type MetaEndFrameCSV struct {
  935. TotalScanned int64
  936. Status int32
  937. SplitsCount int32
  938. RowsCount int64
  939. ColumnsCount int32
  940. ErrorMsg string
  941. }
  942. // MetaEndFrameJSON is MetaEndFrameJSON of CreateSelectObjectMeta
  943. type MetaEndFrameJSON struct {
  944. TotalScanned int64
  945. Status int32
  946. SplitsCount int32
  947. RowsCount int64
  948. ErrorMsg string
  949. }