type.go 47 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078
  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. VersionExpiration *LifecycleVersionExpiration `xml:"NoncurrentVersionExpiration,omitempty"`
  50. VersionTransition *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.VersionExpiration == nil && rule.VersionTransition == nil {
  133. return fmt.Errorf("invalid rule, must set one of Expiration, AbortMultipartUplaod, VersionExpiration, VersionTransition 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. Owner Owner `xml:"Owner"` // Bucket owner
  264. StorageClass string `xml:"StorageClass"` // Bucket storage class
  265. SseRule SSERule `xml:"ServerSideEncryptionRule"` // Bucket ServerSideEncryptionRule
  266. Versioning string `xml:"Versioning"` // Bucket Versioning
  267. }
  268. type SSERule struct {
  269. XMLName xml.Name `xml:"ServerSideEncryptionRule"` // Bucket ServerSideEncryptionRule
  270. KMSMasterKeyID string `xml:"KMSMasterKeyID"` // Bucket KMSMasterKeyID
  271. SSEAlgorithm string `xml:"SSEAlgorithm"` // Bucket SSEAlgorithm
  272. }
  273. // ListObjectsResult defines the result from ListObjects request
  274. type ListObjectsResult struct {
  275. XMLName xml.Name `xml:"ListBucketResult"`
  276. Prefix string `xml:"Prefix"` // The object prefix
  277. Marker string `xml:"Marker"` // The marker filter.
  278. MaxKeys int `xml:"MaxKeys"` // Max keys to return
  279. Delimiter string `xml:"Delimiter"` // The delimiter for grouping objects' name
  280. IsTruncated bool `xml:"IsTruncated"` // Flag indicates if all results are returned (when it's false)
  281. NextMarker string `xml:"NextMarker"` // The start point of the next query
  282. Objects []ObjectProperties `xml:"Contents"` // Object list
  283. CommonPrefixes []string `xml:"CommonPrefixes>Prefix"` // You can think of commonprefixes as "folders" whose names end with the delimiter
  284. }
  285. // ObjectProperties defines Objecct properties
  286. type ObjectProperties struct {
  287. XMLName xml.Name `xml:"Contents"`
  288. Key string `xml:"Key"` // Object key
  289. Type string `xml:"Type"` // Object type
  290. Size int64 `xml:"Size"` // Object size
  291. ETag string `xml:"ETag"` // Object ETag
  292. Owner Owner `xml:"Owner"` // Object owner information
  293. LastModified time.Time `xml:"LastModified"` // Object last modified time
  294. StorageClass string `xml:"StorageClass"` // Object storage class (Standard, IA, Archive)
  295. }
  296. // ListObjectVersionsResult defines the result from ListObjectVersions request
  297. type ListObjectVersionsResult struct {
  298. XMLName xml.Name `xml:"ListVersionsResult"`
  299. Name string `xml:"Name"` // The Bucket Name
  300. Owner Owner `xml:"Owner"` // The owner of bucket
  301. Prefix string `xml:"Prefix"` // The object prefix
  302. KeyMarker string `xml:"KeyMarker"` // The start marker filter.
  303. VersionIdMarker string `xml:"VersionIdMarker"` // The start VersionIdMarker filter.
  304. MaxKeys int `xml:"MaxKeys"` // Max keys to return
  305. Delimiter string `xml:"Delimiter"` // The delimiter for grouping objects' name
  306. IsTruncated bool `xml:"IsTruncated"` // Flag indicates if all results are returned (when it's false)
  307. NextKeyMarker string `xml:"NextKeyMarker"` // The start point of the next query
  308. NextVersionIdMarker string `xml:"NextVersionIdMarker"` // The start point of the next query
  309. CommonPrefixes []string `xml:"CommonPrefixes>Prefix"` // You can think of commonprefixes as "folders" whose names end with the delimiter
  310. ObjectDeleteMarkers []ObjectDeleteMarkerProperties `xml:"DeleteMarker"` // DeleteMarker list
  311. ObjectVersions []ObjectVersionProperties `xml:"Version"` // version list
  312. }
  313. type ObjectDeleteMarkerProperties struct {
  314. XMLName xml.Name `xml:"DeleteMarker"`
  315. Key string `xml:"Key"` // The Object Key
  316. VersionId string `xml:"VersionId"` // The Object VersionId
  317. IsLatest bool `xml:"IsLatest"` // is current version or not
  318. LastModified time.Time `xml:"LastModified"` // Object last modified time
  319. Owner Owner `xml:"Owner"` // bucket owner element
  320. }
  321. type ObjectVersionProperties struct {
  322. XMLName xml.Name `xml:"Version"`
  323. Key string `xml:"Key"` // The Object Key
  324. VersionId string `xml:"VersionId"` // The Object VersionId
  325. IsLatest bool `xml:"IsLatest"` // is latest version or not
  326. LastModified time.Time `xml:"LastModified"` // Object last modified time
  327. Type string `xml:"Type"` // Object type
  328. Size int64 `xml:"Size"` // Object size
  329. ETag string `xml:"ETag"` // Object ETag
  330. StorageClass string `xml:"StorageClass"` // Object storage class (Standard, IA, Archive)
  331. Owner Owner `xml:"Owner"` // bucket owner element
  332. }
  333. // Owner defines Bucket/Object's owner
  334. type Owner struct {
  335. XMLName xml.Name `xml:"Owner"`
  336. ID string `xml:"ID"` // Owner ID
  337. DisplayName string `xml:"DisplayName"` // Owner's display name
  338. }
  339. // CopyObjectResult defines result object of CopyObject
  340. type CopyObjectResult struct {
  341. XMLName xml.Name `xml:"CopyObjectResult"`
  342. LastModified time.Time `xml:"LastModified"` // New object's last modified time.
  343. ETag string `xml:"ETag"` // New object's ETag
  344. }
  345. // GetObjectACLResult defines result of GetObjectACL request
  346. type GetObjectACLResult GetBucketACLResult
  347. type deleteXML struct {
  348. XMLName xml.Name `xml:"Delete"`
  349. Objects []DeleteObject `xml:"Object"` // Objects to delete
  350. Quiet bool `xml:"Quiet"` // Flag of quiet mode.
  351. }
  352. // DeleteObject defines the struct for deleting object
  353. type DeleteObject struct {
  354. XMLName xml.Name `xml:"Object"`
  355. Key string `xml:"Key"` // Object name
  356. VersionId string `xml:"VersionId,omitempty"` // Object VersionId
  357. }
  358. // DeleteObjectsResult defines result of DeleteObjects request
  359. type DeleteObjectsResult struct {
  360. XMLName xml.Name
  361. DeletedObjects []string // Deleted object key list
  362. }
  363. // DeleteObjectsResult_inner defines result of DeleteObjects request
  364. type DeleteObjectVersionsResult struct {
  365. XMLName xml.Name `xml:"DeleteResult"`
  366. DeletedObjectsDetail []DeletedKeyInfo `xml:"Deleted"` // Deleted object detail info
  367. }
  368. // DeleteKeyInfo defines object delete info
  369. type DeletedKeyInfo struct {
  370. XMLName xml.Name `xml:"Deleted"`
  371. Key string `xml:"Key"` // Object key
  372. VersionId string `xml:"VersionId"` // VersionId
  373. DeleteMarker bool `xml:"DeleteMarker"` // Object DeleteMarker
  374. DeleteMarkerVersionId string `xml:"DeleteMarkerVersionId"` // Object DeleteMarkerVersionId
  375. }
  376. // InitiateMultipartUploadResult defines result of InitiateMultipartUpload request
  377. type InitiateMultipartUploadResult struct {
  378. XMLName xml.Name `xml:"InitiateMultipartUploadResult"`
  379. Bucket string `xml:"Bucket"` // Bucket name
  380. Key string `xml:"Key"` // Object name to upload
  381. UploadID string `xml:"UploadId"` // Generated UploadId
  382. }
  383. // UploadPart defines the upload/copy part
  384. type UploadPart struct {
  385. XMLName xml.Name `xml:"Part"`
  386. PartNumber int `xml:"PartNumber"` // Part number
  387. ETag string `xml:"ETag"` // ETag value of the part's data
  388. }
  389. type uploadParts []UploadPart
  390. func (slice uploadParts) Len() int {
  391. return len(slice)
  392. }
  393. func (slice uploadParts) Less(i, j int) bool {
  394. return slice[i].PartNumber < slice[j].PartNumber
  395. }
  396. func (slice uploadParts) Swap(i, j int) {
  397. slice[i], slice[j] = slice[j], slice[i]
  398. }
  399. // UploadPartCopyResult defines result object of multipart copy request.
  400. type UploadPartCopyResult struct {
  401. XMLName xml.Name `xml:"CopyPartResult"`
  402. LastModified time.Time `xml:"LastModified"` // Last modified time
  403. ETag string `xml:"ETag"` // ETag
  404. }
  405. type completeMultipartUploadXML struct {
  406. XMLName xml.Name `xml:"CompleteMultipartUpload"`
  407. Part []UploadPart `xml:"Part"`
  408. }
  409. // CompleteMultipartUploadResult defines result object of CompleteMultipartUploadRequest
  410. type CompleteMultipartUploadResult struct {
  411. XMLName xml.Name `xml:"CompleteMultipartUploadResult"`
  412. Location string `xml:"Location"` // Object URL
  413. Bucket string `xml:"Bucket"` // Bucket name
  414. ETag string `xml:"ETag"` // Object ETag
  415. Key string `xml:"Key"` // Object name
  416. }
  417. // ListUploadedPartsResult defines result object of ListUploadedParts
  418. type ListUploadedPartsResult struct {
  419. XMLName xml.Name `xml:"ListPartsResult"`
  420. Bucket string `xml:"Bucket"` // Bucket name
  421. Key string `xml:"Key"` // Object name
  422. UploadID string `xml:"UploadId"` // Upload ID
  423. NextPartNumberMarker string `xml:"NextPartNumberMarker"` // Next part number
  424. MaxParts int `xml:"MaxParts"` // Max parts count
  425. IsTruncated bool `xml:"IsTruncated"` // Flag indicates all entries returned.false: all entries returned.
  426. UploadedParts []UploadedPart `xml:"Part"` // Uploaded parts
  427. }
  428. // UploadedPart defines uploaded part
  429. type UploadedPart struct {
  430. XMLName xml.Name `xml:"Part"`
  431. PartNumber int `xml:"PartNumber"` // Part number
  432. LastModified time.Time `xml:"LastModified"` // Last modified time
  433. ETag string `xml:"ETag"` // ETag cache
  434. Size int `xml:"Size"` // Part size
  435. }
  436. // ListMultipartUploadResult defines result object of ListMultipartUpload
  437. type ListMultipartUploadResult struct {
  438. XMLName xml.Name `xml:"ListMultipartUploadsResult"`
  439. Bucket string `xml:"Bucket"` // Bucket name
  440. Delimiter string `xml:"Delimiter"` // Delimiter for grouping object.
  441. Prefix string `xml:"Prefix"` // Object prefix
  442. KeyMarker string `xml:"KeyMarker"` // Object key marker
  443. UploadIDMarker string `xml:"UploadIdMarker"` // UploadId marker
  444. NextKeyMarker string `xml:"NextKeyMarker"` // Next key marker, if not all entries returned.
  445. NextUploadIDMarker string `xml:"NextUploadIdMarker"` // Next uploadId marker, if not all entries returned.
  446. MaxUploads int `xml:"MaxUploads"` // Max uploads to return
  447. IsTruncated bool `xml:"IsTruncated"` // Flag indicates all entries are returned.
  448. Uploads []UncompletedUpload `xml:"Upload"` // Ongoing uploads (not completed, not aborted)
  449. CommonPrefixes []string `xml:"CommonPrefixes>Prefix"` // Common prefixes list.
  450. }
  451. // UncompletedUpload structure wraps an uncompleted upload task
  452. type UncompletedUpload struct {
  453. XMLName xml.Name `xml:"Upload"`
  454. Key string `xml:"Key"` // Object name
  455. UploadID string `xml:"UploadId"` // The UploadId
  456. Initiated time.Time `xml:"Initiated"` // Initialization time in the format such as 2012-02-23T04:18:23.000Z
  457. }
  458. // ProcessObjectResult defines result object of ProcessObject
  459. type ProcessObjectResult struct {
  460. Bucket string `json:"bucket"`
  461. FileSize int `json:"fileSize"`
  462. Object string `json:"object"`
  463. Status string `json:"status"`
  464. }
  465. // decodeDeleteObjectsResult decodes deleting objects result in URL encoding
  466. func decodeDeleteObjectsResult(result *DeleteObjectVersionsResult) error {
  467. var err error
  468. for i := 0; i < len(result.DeletedObjectsDetail); i++ {
  469. result.DeletedObjectsDetail[i].Key, err = url.QueryUnescape(result.DeletedObjectsDetail[i].Key)
  470. if err != nil {
  471. return err
  472. }
  473. }
  474. return nil
  475. }
  476. // decodeListObjectsResult decodes list objects result in URL encoding
  477. func decodeListObjectsResult(result *ListObjectsResult) error {
  478. var err error
  479. result.Prefix, err = url.QueryUnescape(result.Prefix)
  480. if err != nil {
  481. return err
  482. }
  483. result.Marker, err = url.QueryUnescape(result.Marker)
  484. if err != nil {
  485. return err
  486. }
  487. result.Delimiter, err = url.QueryUnescape(result.Delimiter)
  488. if err != nil {
  489. return err
  490. }
  491. result.NextMarker, err = url.QueryUnescape(result.NextMarker)
  492. if err != nil {
  493. return err
  494. }
  495. for i := 0; i < len(result.Objects); i++ {
  496. result.Objects[i].Key, err = url.QueryUnescape(result.Objects[i].Key)
  497. if err != nil {
  498. return err
  499. }
  500. }
  501. for i := 0; i < len(result.CommonPrefixes); i++ {
  502. result.CommonPrefixes[i], err = url.QueryUnescape(result.CommonPrefixes[i])
  503. if err != nil {
  504. return err
  505. }
  506. }
  507. return nil
  508. }
  509. // decodeListObjectVersionsResult decodes list version objects result in URL encoding
  510. func decodeListObjectVersionsResult(result *ListObjectVersionsResult) error {
  511. var err error
  512. // decode:Delimiter
  513. result.Delimiter, err = url.QueryUnescape(result.Delimiter)
  514. if err != nil {
  515. return err
  516. }
  517. // decode Prefix
  518. result.Prefix, err = url.QueryUnescape(result.Prefix)
  519. if err != nil {
  520. return err
  521. }
  522. // decode KeyMarker
  523. result.KeyMarker, err = url.QueryUnescape(result.KeyMarker)
  524. if err != nil {
  525. return err
  526. }
  527. // decode VersionIdMarker
  528. result.VersionIdMarker, err = url.QueryUnescape(result.VersionIdMarker)
  529. if err != nil {
  530. return err
  531. }
  532. // decode NextKeyMarker
  533. result.NextKeyMarker, err = url.QueryUnescape(result.NextKeyMarker)
  534. if err != nil {
  535. return err
  536. }
  537. // decode NextVersionIdMarker
  538. result.NextVersionIdMarker, err = url.QueryUnescape(result.NextVersionIdMarker)
  539. if err != nil {
  540. return err
  541. }
  542. // decode CommonPrefixes
  543. for i := 0; i < len(result.CommonPrefixes); i++ {
  544. result.CommonPrefixes[i], err = url.QueryUnescape(result.CommonPrefixes[i])
  545. if err != nil {
  546. return err
  547. }
  548. }
  549. // decode deleteMarker
  550. for i := 0; i < len(result.ObjectDeleteMarkers); i++ {
  551. result.ObjectDeleteMarkers[i].Key, err = url.QueryUnescape(result.ObjectDeleteMarkers[i].Key)
  552. if err != nil {
  553. return err
  554. }
  555. }
  556. // decode ObjectVersions
  557. for i := 0; i < len(result.ObjectVersions); i++ {
  558. result.ObjectVersions[i].Key, err = url.QueryUnescape(result.ObjectVersions[i].Key)
  559. if err != nil {
  560. return err
  561. }
  562. }
  563. return nil
  564. }
  565. // decodeListUploadedPartsResult decodes
  566. func decodeListUploadedPartsResult(result *ListUploadedPartsResult) error {
  567. var err error
  568. result.Key, err = url.QueryUnescape(result.Key)
  569. if err != nil {
  570. return err
  571. }
  572. return nil
  573. }
  574. // decodeListMultipartUploadResult decodes list multipart upload result in URL encoding
  575. func decodeListMultipartUploadResult(result *ListMultipartUploadResult) error {
  576. var err error
  577. result.Prefix, err = url.QueryUnescape(result.Prefix)
  578. if err != nil {
  579. return err
  580. }
  581. result.Delimiter, err = url.QueryUnescape(result.Delimiter)
  582. if err != nil {
  583. return err
  584. }
  585. result.KeyMarker, err = url.QueryUnescape(result.KeyMarker)
  586. if err != nil {
  587. return err
  588. }
  589. result.NextKeyMarker, err = url.QueryUnescape(result.NextKeyMarker)
  590. if err != nil {
  591. return err
  592. }
  593. for i := 0; i < len(result.Uploads); i++ {
  594. result.Uploads[i].Key, err = url.QueryUnescape(result.Uploads[i].Key)
  595. if err != nil {
  596. return err
  597. }
  598. }
  599. for i := 0; i < len(result.CommonPrefixes); i++ {
  600. result.CommonPrefixes[i], err = url.QueryUnescape(result.CommonPrefixes[i])
  601. if err != nil {
  602. return err
  603. }
  604. }
  605. return nil
  606. }
  607. // createBucketConfiguration defines the configuration for creating a bucket.
  608. type createBucketConfiguration struct {
  609. XMLName xml.Name `xml:"CreateBucketConfiguration"`
  610. StorageClass StorageClassType `xml:"StorageClass,omitempty"`
  611. }
  612. // LiveChannelConfiguration defines the configuration for live-channel
  613. type LiveChannelConfiguration struct {
  614. XMLName xml.Name `xml:"LiveChannelConfiguration"`
  615. Description string `xml:"Description,omitempty"` //Description of live-channel, up to 128 bytes
  616. Status string `xml:"Status,omitempty"` //Specify the status of livechannel
  617. Target LiveChannelTarget `xml:"Target"` //target configuration of live-channel
  618. // use point instead of struct to avoid omit empty snapshot
  619. Snapshot *LiveChannelSnapshot `xml:"Snapshot,omitempty"` //snapshot configuration of live-channel
  620. }
  621. // LiveChannelTarget target configuration of live-channel
  622. type LiveChannelTarget struct {
  623. XMLName xml.Name `xml:"Target"`
  624. Type string `xml:"Type"` //the type of object, only supports HLS
  625. FragDuration int `xml:"FragDuration,omitempty"` //the length of each ts object (in seconds), in the range [1,100]
  626. FragCount int `xml:"FragCount,omitempty"` //the number of ts objects in the m3u8 object, in the range of [1,100]
  627. PlaylistName string `xml:"PlaylistName,omitempty"` //the name of m3u8 object, which must end with ".m3u8" and the length range is [6,128]
  628. }
  629. // LiveChannelSnapshot snapshot configuration of live-channel
  630. type LiveChannelSnapshot struct {
  631. XMLName xml.Name `xml:"Snapshot"`
  632. 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.
  633. DestBucket string `xml:"DestBucket,omitempty"` //Bucket the snapshots will be written to. should be the same owner as the source bucket.
  634. NotifyTopic string `xml:"NotifyTopic,omitempty"` //Topics of MNS for notifying users of high frequency screenshot operation results
  635. Interval int `xml:"Interval,omitempty"` //interval of snapshots, threre is no snapshot if no I-frame during the interval time
  636. }
  637. // CreateLiveChannelResult the result of crete live-channel
  638. type CreateLiveChannelResult struct {
  639. XMLName xml.Name `xml:"CreateLiveChannelResult"`
  640. PublishUrls []string `xml:"PublishUrls>Url"` //push urls list
  641. PlayUrls []string `xml:"PlayUrls>Url"` //play urls list
  642. }
  643. // LiveChannelStat the result of get live-channel state
  644. type LiveChannelStat struct {
  645. XMLName xml.Name `xml:"LiveChannelStat"`
  646. Status string `xml:"Status"` //Current push status of live-channel: Disabled,Live,Idle
  647. ConnectedTime time.Time `xml:"ConnectedTime"` //The time when the client starts pushing, format: ISO8601
  648. RemoteAddr string `xml:"RemoteAddr"` //The ip address of the client
  649. Video LiveChannelVideo `xml:"Video"` //Video stream information
  650. Audio LiveChannelAudio `xml:"Audio"` //Audio stream information
  651. }
  652. // LiveChannelVideo video stream information
  653. type LiveChannelVideo struct {
  654. XMLName xml.Name `xml:"Video"`
  655. Width int `xml:"Width"` //Width (unit: pixels)
  656. Height int `xml:"Height"` //Height (unit: pixels)
  657. FrameRate int `xml:"FrameRate"` //FramRate
  658. Bandwidth int `xml:"Bandwidth"` //Bandwidth (unit: B/s)
  659. }
  660. // LiveChannelAudio audio stream information
  661. type LiveChannelAudio struct {
  662. XMLName xml.Name `xml:"Audio"`
  663. SampleRate int `xml:"SampleRate"` //SampleRate
  664. Bandwidth int `xml:"Bandwidth"` //Bandwidth (unit: B/s)
  665. Codec string `xml:"Codec"` //Encoding forma
  666. }
  667. // LiveChannelHistory the result of GetLiveChannelHistory, at most return up to lastest 10 push records
  668. type LiveChannelHistory struct {
  669. XMLName xml.Name `xml:"LiveChannelHistory"`
  670. Record []LiveRecord `xml:"LiveRecord"` //push records list
  671. }
  672. // LiveRecord push recode
  673. type LiveRecord struct {
  674. XMLName xml.Name `xml:"LiveRecord"`
  675. StartTime time.Time `xml:"StartTime"` //StartTime, format: ISO8601
  676. EndTime time.Time `xml:"EndTime"` //EndTime, format: ISO8601
  677. RemoteAddr string `xml:"RemoteAddr"` //The ip address of remote client
  678. }
  679. // ListLiveChannelResult the result of ListLiveChannel
  680. type ListLiveChannelResult struct {
  681. XMLName xml.Name `xml:"ListLiveChannelResult"`
  682. Prefix string `xml:"Prefix"` //Filter by the name start with the value of "Prefix"
  683. Marker string `xml:"Marker"` //cursor from which starting list
  684. MaxKeys int `xml:"MaxKeys"` //The maximum count returned. the default value is 100. it cannot be greater than 1000.
  685. IsTruncated bool `xml:"IsTruncated"` //Indicates whether all results have been returned, "true" indicates partial results returned while "false" indicates all results have been returned
  686. NextMarker string `xml:"NextMarker"` //NextMarker indicate the Marker value of the next request
  687. LiveChannel []LiveChannelInfo `xml:"LiveChannel"` //The infomation of live-channel
  688. }
  689. // LiveChannelInfo the infomation of live-channel
  690. type LiveChannelInfo struct {
  691. XMLName xml.Name `xml:"LiveChannel"`
  692. Name string `xml:"Name"` //The name of live-channel
  693. Description string `xml:"Description"` //Description of live-channel
  694. Status string `xml:"Status"` //Status: disabled or enabled
  695. LastModified time.Time `xml:"LastModified"` //Last modification time, format: ISO8601
  696. PublishUrls []string `xml:"PublishUrls>Url"` //push urls list
  697. PlayUrls []string `xml:"PlayUrls>Url"` //play urls list
  698. }
  699. // Tag a tag for the object
  700. type Tag struct {
  701. XMLName xml.Name `xml:"Tag"`
  702. Key string `xml:"Key"`
  703. Value string `xml:"Value"`
  704. }
  705. // Tagging tagset for the object
  706. type Tagging struct {
  707. XMLName xml.Name `xml:"Tagging"`
  708. Tags []Tag `xml:"TagSet>Tag,omitempty"`
  709. }
  710. // for GetObjectTagging return value
  711. type GetObjectTaggingResult Tagging
  712. // VersioningConfig for the bucket
  713. type VersioningConfig struct {
  714. XMLName xml.Name `xml:"VersioningConfiguration"`
  715. Status string `xml:"Status"`
  716. }
  717. type GetBucketVersioningResult VersioningConfig
  718. // Server Encryption rule for the bucket
  719. type ServerEncryptionRule struct {
  720. XMLName xml.Name `xml:"ServerSideEncryptionRule"`
  721. SSEDefault SSEDefaultRule `xml:"ApplyServerSideEncryptionByDefault"`
  722. }
  723. // Server Encryption deafult rule for the bucket
  724. type SSEDefaultRule struct {
  725. XMLName xml.Name `xml:"ApplyServerSideEncryptionByDefault"`
  726. SSEAlgorithm string `xml:"SSEAlgorithm"`
  727. KMSMasterKeyID string `xml:"KMSMasterKeyID"`
  728. }
  729. type GetBucketEncryptionResult ServerEncryptionRule
  730. type GetBucketTaggingResult Tagging
  731. type BucketStat struct {
  732. XMLName xml.Name `xml:"BucketStat"`
  733. Storage int64 `xml:"Storage"`
  734. ObjectCount int64 `xml:"ObjectCount"`
  735. MultipartUploadCount int64 `xml:"MultipartUploadCount"`
  736. }
  737. type GetBucketStatResult BucketStat
  738. // RequestPaymentConfiguration define the request payment configuration
  739. type RequestPaymentConfiguration struct {
  740. XMLName xml.Name `xml:"RequestPaymentConfiguration"`
  741. Payer string `xml:"Payer,omitempty"`
  742. }
  743. // BucketQoSConfiguration define QoS configuration
  744. type BucketQoSConfiguration struct {
  745. XMLName xml.Name `xml:"QoSConfiguration"`
  746. TotalUploadBandwidth *int `xml:"TotalUploadBandwidth"` // Total upload bandwidth
  747. IntranetUploadBandwidth *int `xml:"IntranetUploadBandwidth"` // Intranet upload bandwidth
  748. ExtranetUploadBandwidth *int `xml:"ExtranetUploadBandwidth"` // Extranet upload bandwidth
  749. TotalDownloadBandwidth *int `xml:"TotalDownloadBandwidth"` // Total download bandwidth
  750. IntranetDownloadBandwidth *int `xml:"IntranetDownloadBandwidth"` // Intranet download bandwidth
  751. ExtranetDownloadBandwidth *int `xml:"ExtranetDownloadBandwidth"` // Extranet download bandwidth
  752. TotalQPS *int `xml:"TotalQps"` // Total Qps
  753. IntranetQPS *int `xml:"IntranetQps"` // Intranet Qps
  754. ExtranetQPS *int `xml:"ExtranetQps"` // Extranet Qps
  755. }
  756. // UserQoSConfiguration define QoS and Range configuration
  757. type UserQoSConfiguration struct {
  758. XMLName xml.Name `xml:"QoSConfiguration"`
  759. Region string `xml:"Region,omitempty"` // Effective area of Qos configuration
  760. BucketQoSConfiguration
  761. }
  762. //////////////////////////////////////////////////////////////
  763. /////////////////// Select OBject ////////////////////////////
  764. //////////////////////////////////////////////////////////////
  765. type CsvMetaRequest struct {
  766. XMLName xml.Name `xml:"CsvMetaRequest"`
  767. InputSerialization InputSerialization `xml:"InputSerialization"`
  768. OverwriteIfExists *bool `xml:"OverwriteIfExists,omitempty"`
  769. }
  770. // encodeBase64 encode base64 of the CreateSelectObjectMeta api request params
  771. func (meta *CsvMetaRequest) encodeBase64() {
  772. meta.InputSerialization.CSV.RecordDelimiter =
  773. base64.StdEncoding.EncodeToString([]byte(meta.InputSerialization.CSV.RecordDelimiter))
  774. meta.InputSerialization.CSV.FieldDelimiter =
  775. base64.StdEncoding.EncodeToString([]byte(meta.InputSerialization.CSV.FieldDelimiter))
  776. meta.InputSerialization.CSV.QuoteCharacter =
  777. base64.StdEncoding.EncodeToString([]byte(meta.InputSerialization.CSV.QuoteCharacter))
  778. }
  779. type JsonMetaRequest struct {
  780. XMLName xml.Name `xml:"JsonMetaRequest"`
  781. InputSerialization InputSerialization `xml:"InputSerialization"`
  782. OverwriteIfExists *bool `xml:"OverwriteIfExists,omitempty"`
  783. }
  784. type InputSerialization struct {
  785. XMLName xml.Name `xml:"InputSerialization"`
  786. CSV CSV `xml:CSV,omitempty`
  787. JSON JSON `xml:JSON,omitempty`
  788. CompressionType string `xml:"CompressionType,omitempty"`
  789. }
  790. type CSV struct {
  791. XMLName xml.Name `xml:"CSV"`
  792. RecordDelimiter string `xml:"RecordDelimiter,omitempty"`
  793. FieldDelimiter string `xml:"FieldDelimiter,omitempty"`
  794. QuoteCharacter string `xml:"QuoteCharacter,omitempty"`
  795. }
  796. type JSON struct {
  797. XMLName xml.Name `xml:"JSON"`
  798. JSONType string `xml:"Type,omitempty"`
  799. }
  800. // SelectRequest is for the SelectObject request params of json file
  801. type SelectRequest struct {
  802. XMLName xml.Name `xml:"SelectRequest"`
  803. Expression string `xml:"Expression"`
  804. InputSerializationSelect InputSerializationSelect `xml:"InputSerialization"`
  805. OutputSerializationSelect OutputSerializationSelect `xml:"OutputSerialization"`
  806. SelectOptions SelectOptions `xml:"Options,omitempty"`
  807. }
  808. type InputSerializationSelect struct {
  809. XMLName xml.Name `xml:"InputSerialization"`
  810. CsvBodyInput CSVSelectInput `xml:CSV,omitempty`
  811. JsonBodyInput JSONSelectInput `xml:JSON,omitempty`
  812. CompressionType string `xml:"CompressionType,omitempty"`
  813. }
  814. type CSVSelectInput struct {
  815. XMLName xml.Name `xml:"CSV"`
  816. FileHeaderInfo string `xml:"FileHeaderInfo,omitempty"`
  817. RecordDelimiter string `xml:"RecordDelimiter,omitempty"`
  818. FieldDelimiter string `xml:"FieldDelimiter,omitempty"`
  819. QuoteCharacter string `xml:"QuoteCharacter,omitempty"`
  820. CommentCharacter string `xml:"CommentCharacter,omitempty"`
  821. Range string `xml:"Range,omitempty"`
  822. SplitRange string
  823. }
  824. type JSONSelectInput struct {
  825. XMLName xml.Name `xml:"JSON"`
  826. JSONType string `xml:"Type,omitempty"`
  827. Range string `xml:"Range,omitempty"`
  828. ParseJSONNumberAsString *bool `xml:"ParseJsonNumberAsString"`
  829. SplitRange string
  830. }
  831. func (jsonInput *JSONSelectInput) JsonIsEmpty() bool {
  832. if jsonInput.JSONType != "" {
  833. return false
  834. }
  835. return true
  836. }
  837. type OutputSerializationSelect struct {
  838. XMLName xml.Name `xml:"OutputSerialization"`
  839. CsvBodyOutput CSVSelectOutput `xml:CSV,omitempty`
  840. JsonBodyOutput JSONSelectOutput `xml:JSON,omitempty`
  841. OutputRawData *bool `xml:"OutputRawData,omitempty"`
  842. KeepAllColumns *bool `xml:"KeepAllColumns,omitempty"`
  843. EnablePayloadCrc *bool `xml:"EnablePayloadCrc,omitempty"`
  844. OutputHeader *bool `xml:"OutputHeader,omitempty"`
  845. }
  846. type CSVSelectOutput struct {
  847. XMLName xml.Name `xml:"CSV"`
  848. RecordDelimiter string `xml:"RecordDelimiter,omitempty"`
  849. FieldDelimiter string `xml:"FieldDelimiter,omitempty"`
  850. }
  851. type JSONSelectOutput struct {
  852. XMLName xml.Name `xml:"JSON"`
  853. RecordDelimiter string `xml:"RecordDelimiter,omitempty"`
  854. }
  855. func (selectReq *SelectRequest) encodeBase64() {
  856. if selectReq.InputSerializationSelect.JsonBodyInput.JsonIsEmpty() {
  857. selectReq.csvEncodeBase64()
  858. } else {
  859. selectReq.jsonEncodeBase64()
  860. }
  861. }
  862. // csvEncodeBase64 encode base64 of the SelectObject api request params
  863. func (selectReq *SelectRequest) csvEncodeBase64() {
  864. selectReq.Expression = base64.StdEncoding.EncodeToString([]byte(selectReq.Expression))
  865. selectReq.InputSerializationSelect.CsvBodyInput.RecordDelimiter =
  866. base64.StdEncoding.EncodeToString([]byte(selectReq.InputSerializationSelect.CsvBodyInput.RecordDelimiter))
  867. selectReq.InputSerializationSelect.CsvBodyInput.FieldDelimiter =
  868. base64.StdEncoding.EncodeToString([]byte(selectReq.InputSerializationSelect.CsvBodyInput.FieldDelimiter))
  869. selectReq.InputSerializationSelect.CsvBodyInput.QuoteCharacter =
  870. base64.StdEncoding.EncodeToString([]byte(selectReq.InputSerializationSelect.CsvBodyInput.QuoteCharacter))
  871. selectReq.InputSerializationSelect.CsvBodyInput.CommentCharacter =
  872. base64.StdEncoding.EncodeToString([]byte(selectReq.InputSerializationSelect.CsvBodyInput.CommentCharacter))
  873. selectReq.OutputSerializationSelect.CsvBodyOutput.FieldDelimiter =
  874. base64.StdEncoding.EncodeToString([]byte(selectReq.OutputSerializationSelect.CsvBodyOutput.FieldDelimiter))
  875. selectReq.OutputSerializationSelect.CsvBodyOutput.RecordDelimiter =
  876. base64.StdEncoding.EncodeToString([]byte(selectReq.OutputSerializationSelect.CsvBodyOutput.RecordDelimiter))
  877. // handle Range
  878. if selectReq.InputSerializationSelect.CsvBodyInput.Range != "" {
  879. selectReq.InputSerializationSelect.CsvBodyInput.Range = "line-range=" + selectReq.InputSerializationSelect.CsvBodyInput.Range
  880. }
  881. if selectReq.InputSerializationSelect.CsvBodyInput.SplitRange != "" {
  882. selectReq.InputSerializationSelect.CsvBodyInput.Range = "split-range=" + selectReq.InputSerializationSelect.CsvBodyInput.SplitRange
  883. }
  884. }
  885. // jsonEncodeBase64 encode base64 of the SelectObject api request params
  886. func (selectReq *SelectRequest) jsonEncodeBase64() {
  887. selectReq.Expression = base64.StdEncoding.EncodeToString([]byte(selectReq.Expression))
  888. selectReq.OutputSerializationSelect.JsonBodyOutput.RecordDelimiter =
  889. base64.StdEncoding.EncodeToString([]byte(selectReq.OutputSerializationSelect.JsonBodyOutput.RecordDelimiter))
  890. // handle Range
  891. if selectReq.InputSerializationSelect.JsonBodyInput.Range != "" {
  892. selectReq.InputSerializationSelect.JsonBodyInput.Range = "line-range=" + selectReq.InputSerializationSelect.JsonBodyInput.Range
  893. }
  894. if selectReq.InputSerializationSelect.JsonBodyInput.SplitRange != "" {
  895. selectReq.InputSerializationSelect.JsonBodyInput.Range = "split-range=" + selectReq.InputSerializationSelect.JsonBodyInput.SplitRange
  896. }
  897. }
  898. // CsvOptions is a element in the SelectObject api request's params
  899. type SelectOptions struct {
  900. XMLName xml.Name `xml:"Options"`
  901. SkipPartialDataRecord *bool `xml:"SkipPartialDataRecord,omitempty"`
  902. MaxSkippedRecordsAllowed string `xml:"MaxSkippedRecordsAllowed,omitempty"`
  903. }
  904. // SelectObjectResult is the SelectObject api's return
  905. type SelectObjectResult struct {
  906. Version byte
  907. FrameType int32
  908. PayloadLength int32
  909. HeaderCheckSum uint32
  910. Offset uint64
  911. Data string // DataFrame
  912. EndFrame EndFrame // EndFrame
  913. MetaEndFrameCSV MetaEndFrameCSV // MetaEndFrameCSV
  914. MetaEndFrameJSON MetaEndFrameJSON // MetaEndFrameJSON
  915. PayloadChecksum uint32
  916. ReadFlagInfo
  917. }
  918. // ReadFlagInfo if reading the frame data, recode the reading status
  919. type ReadFlagInfo struct {
  920. OpenLine bool
  921. ConsumedBytesLength int32
  922. EnablePayloadCrc bool
  923. OutputRawData bool
  924. }
  925. // EndFrame is EndFrameType of SelectObject api
  926. type EndFrame struct {
  927. TotalScanned int64
  928. HTTPStatusCode int32
  929. ErrorMsg string
  930. }
  931. // MetaEndFrameCSV is MetaEndFrameCSVType of CreateSelectObjectMeta
  932. type MetaEndFrameCSV struct {
  933. TotalScanned int64
  934. Status int32
  935. SplitsCount int32
  936. RowsCount int64
  937. ColumnsCount int32
  938. ErrorMsg string
  939. }
  940. // MetaEndFrameJSON is MetaEndFrameJSON of CreateSelectObjectMeta
  941. type MetaEndFrameJSON struct {
  942. TotalScanned int64
  943. Status int32
  944. SplitsCount int32
  945. RowsCount int64
  946. ErrorMsg string
  947. }