type.go 46 KB

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