type.go 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643
  1. package oss
  2. import (
  3. "encoding/xml"
  4. "fmt"
  5. "net/url"
  6. "time"
  7. )
  8. // ListBucketsResult defines the result object from ListBuckets request
  9. type ListBucketsResult struct {
  10. XMLName xml.Name `xml:"ListAllMyBucketsResult"`
  11. Prefix string `xml:"Prefix"` // The prefix in this query
  12. Marker string `xml:"Marker"` // The marker filter
  13. MaxKeys int `xml:"MaxKeys"` // The max entry count to return. This information is returned when IsTruncated is true.
  14. IsTruncated bool `xml:"IsTruncated"` // Flag true means there's remaining buckets to return.
  15. NextMarker string `xml:"NextMarker"` // The marker filter for the next list call
  16. Owner Owner `xml:"Owner"` // The owner information
  17. Buckets []BucketProperties `xml:"Buckets>Bucket"` // The bucket list
  18. }
  19. // BucketProperties defines bucket properties
  20. type BucketProperties struct {
  21. XMLName xml.Name `xml:"Bucket"`
  22. Name string `xml:"Name"` // Bucket name
  23. Location string `xml:"Location"` // Bucket datacenter
  24. CreationDate time.Time `xml:"CreationDate"` // Bucket create time
  25. StorageClass string `xml:"StorageClass"` // Bucket storage class
  26. }
  27. // GetBucketACLResult defines GetBucketACL request's result
  28. type GetBucketACLResult struct {
  29. XMLName xml.Name `xml:"AccessControlPolicy"`
  30. ACL string `xml:"AccessControlList>Grant"` // Bucket ACL
  31. Owner Owner `xml:"Owner"` // Bucket owner
  32. }
  33. // LifecycleConfiguration is the Bucket Lifecycle configuration
  34. type LifecycleConfiguration struct {
  35. XMLName xml.Name `xml:"LifecycleConfiguration"`
  36. Rules []LifecycleRule `xml:"Rule"`
  37. }
  38. // LifecycleRule defines Lifecycle rules
  39. type LifecycleRule struct {
  40. XMLName xml.Name `xml:"Rule"`
  41. ID string `xml:"ID"` // The rule ID
  42. Prefix string `xml:"Prefix"` // The object key prefix
  43. Status string `xml:"Status"` // The rule status (enabled or not)
  44. Expiration *LifecycleExpiration `xml:"Expiration,omitempty"` // The expiration property
  45. Transition *LifecycleTransition `xml:"Transition,omitempty"` // The transition property
  46. AbortMultipartUpload *LifecycleAbortMultipartUpload `xml:AbortMultipartUpload,omitempty` // The AbortMultipartUpload property
  47. }
  48. // LifecycleExpiration defines the rule's expiration property
  49. type LifecycleExpiration struct {
  50. XMLName xml.Name `xml:"Expiration"`
  51. Days int `xml:"Days,omitempty"` // Relative expiration time: The expiration time in days after the last modified time
  52. //Date *time.Time `xml:"Date,omitempty"` // Absolute expiration time: The expiration time in date.
  53. //CreatedBeforeDate *time.Time `xml:"CreatedBeforeDate,omitempty"` // objects created before the date will be expired
  54. Date string `xml:"Date,omitempty"` // Absolute expiration time: The expiration time in date.
  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 *time.Time `xml:"CreatedBeforeDate,omitempty"` // objects created before the date will be restored
  62. CreatedBeforeDate string `xml:"CreatedBeforeDate,omitempty"` // objects created before the date will be expired
  63. StorageClass StorageClassType `xml:"StorageClass,omitempty"` // Specifies the target storage type
  64. }
  65. // LifecycleAbortMultipartUpload defines the rule's abort multipart upload propery
  66. type LifecycleAbortMultipartUpload struct {
  67. XMLName xml.Name `xml:"AbortMultipartUpload"`
  68. Days int `xml:"Days,omitempty"` // Relative expiration time: The expiration time in days after the last modified time
  69. //CreatedBeforeDate *time.Time `xml:"CreatedBeforeDate,omitempty"` // objects created before the date will be expired
  70. CreatedBeforeDate string `xml:"CreatedBeforeDate,omitempty"` // objects created before the date will be expired
  71. }
  72. /*
  73. type lifecycleXML struct {
  74. XMLName xml.Name `xml:"LifecycleConfiguration"`
  75. Rules []lifecycleRule `xml:"Rule"`
  76. }
  77. type lifecycleRule struct {
  78. XMLName xml.Name `xml:"Rule"`
  79. ID string `xml:"ID"`
  80. Prefix string `xml:"Prefix"`
  81. Status string `xml:"Status"`
  82. Expiration lifecycleExpiration `xml:"Expiration"`
  83. }
  84. type lifecycleExpiration struct {
  85. XMLName xml.Name `xml:"Expiration"`
  86. Days int `xml:"Days,omitempty"`
  87. Date string `xml:"Date,omitempty"`
  88. }
  89. const expirationDateFormat = "2006-01-02T15:04:05.000Z"
  90. func convLifecycleRule(rules []LifecycleRule) []lifecycleRule {
  91. rs := []lifecycleRule{}
  92. for _, rule := range rules {
  93. r := lifecycleRule{}
  94. r.ID = rule.ID
  95. r.Prefix = rule.Prefix
  96. r.Status = rule.Status
  97. if rule.Expiration.Date.IsZero() {
  98. r.Expiration.Days = rule.Expiration.Days
  99. } else {
  100. r.Expiration.Date = rule.Expiration.Date.Format(expirationDateFormat)
  101. }
  102. rs = append(rs, r)
  103. }
  104. return rs
  105. }
  106. */
  107. const iso8601DateFormat = "2006-01-02T15:04:05.000Z"
  108. // BuildLifecycleRuleByDays builds a lifecycle rule objects will expiration in days after the last modified time
  109. func BuildLifecycleRuleByDays(id, prefix string, status bool, days int) LifecycleRule {
  110. var statusStr = "Enabled"
  111. if !status {
  112. statusStr = "Disabled"
  113. }
  114. return LifecycleRule{ID: id, Prefix: prefix, Status: statusStr,
  115. Expiration: &LifecycleExpiration{Days: days}}
  116. }
  117. // BuildLifecycleRuleByDate builds a lifecycle rule objects will expiration in specified date
  118. func BuildLifecycleRuleByDate(id, prefix string, status bool, year, month, day int) LifecycleRule {
  119. var statusStr = "Enabled"
  120. if !status {
  121. statusStr = "Disabled"
  122. }
  123. date := time.Date(year, time.Month(month), day, 0, 0, 0, 0, time.UTC).Format(iso8601DateFormat)
  124. return LifecycleRule{ID: id, Prefix: prefix, Status: statusStr,
  125. Expiration: &LifecycleExpiration{Date: date}}
  126. }
  127. // NewLifecleRuleByDays builds a lifecycle rule objects will expiration in days after the last modified time
  128. func NewLifecleRuleByDays(id, prefix string, status bool, days int, lrt LifecycleRuleType, sc StorageClassType) (*LifecycleRule, error) {
  129. var statusStr = "Enabled"
  130. if !status {
  131. statusStr = "Disabled"
  132. }
  133. switch lrt {
  134. case LRTExpriration:
  135. return &LifecycleRule{ID: id, Prefix: prefix, Status: statusStr,
  136. Expiration: &LifecycleExpiration{Days: days}}, nil
  137. case LRTTransition:
  138. if sc != StorageIA && sc != StorageArchive {
  139. return nil, fmt.Errorf("invalid storage class of transition lifecycle rule, storage class: %v", sc)
  140. }
  141. return &LifecycleRule{ID: id, Prefix: prefix, Status: statusStr,
  142. Transition: &LifecycleTransition{Days: days, StorageClass: sc}}, nil
  143. case LRTAbortMultiPartUpload:
  144. return &LifecycleRule{ID: id, Prefix: prefix, Status: statusStr,
  145. AbortMultipartUpload: &LifecycleAbortMultipartUpload{Days: days}}, nil
  146. default:
  147. return nil, fmt.Errorf("invalid type of lifecycle rule: %v", lrt)
  148. }
  149. }
  150. // NewLifecycleRuleByCreateBeforeDate builds a lifecycle rule objects created before the date will be expired.
  151. func NewLifecycleRuleByCreateBeforeDate(id, prefix string, status bool, year, month, day int, lrt LifecycleRuleType, sc StorageClassType) (*LifecycleRule, error) {
  152. var statusStr = "Enabled"
  153. if !status {
  154. statusStr = "Disabled"
  155. }
  156. date := time.Date(year, time.Month(month), day, 0, 0, 0, 0, time.UTC).Format(iso8601DateFormat)
  157. switch lrt {
  158. case LRTExpriration:
  159. return &LifecycleRule{ID: id, Prefix: prefix, Status: statusStr,
  160. Expiration: &LifecycleExpiration{CreatedBeforeDate: date}}, nil
  161. case LRTTransition:
  162. if sc != StorageIA && sc != StorageArchive {
  163. return nil, fmt.Errorf("invalid storage class of transition lifecycle rule, storage class: %v", sc)
  164. }
  165. return &LifecycleRule{ID: id, Prefix: prefix, Status: statusStr,
  166. Transition: &LifecycleTransition{CreatedBeforeDate: date, StorageClass: sc}}, nil
  167. case LRTAbortMultiPartUpload:
  168. return &LifecycleRule{ID: id, Prefix: prefix, Status: statusStr,
  169. AbortMultipartUpload: &LifecycleAbortMultipartUpload{CreatedBeforeDate: date}}, nil
  170. default:
  171. return nil, fmt.Errorf("invalid type of lifecycle rule: %v", lrt)
  172. }
  173. }
  174. // GetBucketLifecycleResult defines GetBucketLifecycle's result object
  175. type GetBucketLifecycleResult LifecycleConfiguration
  176. // RefererXML defines Referer configuration
  177. type RefererXML struct {
  178. XMLName xml.Name `xml:"RefererConfiguration"`
  179. AllowEmptyReferer bool `xml:"AllowEmptyReferer"` // Allow empty referrer
  180. RefererList []string `xml:"RefererList>Referer"` // Referer whitelist
  181. }
  182. // GetBucketRefererResult defines result object for GetBucketReferer request
  183. type GetBucketRefererResult RefererXML
  184. // LoggingXML defines logging configuration
  185. type LoggingXML struct {
  186. XMLName xml.Name `xml:"BucketLoggingStatus"`
  187. LoggingEnabled LoggingEnabled `xml:"LoggingEnabled"` // The logging configuration information
  188. }
  189. type loggingXMLEmpty struct {
  190. XMLName xml.Name `xml:"BucketLoggingStatus"`
  191. }
  192. // LoggingEnabled defines the logging configuration information
  193. type LoggingEnabled struct {
  194. XMLName xml.Name `xml:"LoggingEnabled"`
  195. TargetBucket string `xml:"TargetBucket"` // The bucket name for storing the log files
  196. TargetPrefix string `xml:"TargetPrefix"` // The log file prefix
  197. }
  198. // GetBucketLoggingResult defines the result from GetBucketLogging request
  199. type GetBucketLoggingResult LoggingXML
  200. // WebsiteXML defines Website configuration
  201. type WebsiteXML struct {
  202. XMLName xml.Name `xml:"WebsiteConfiguration"`
  203. IndexDocument IndexDocument `xml:"IndexDocument"` // The index page
  204. ErrorDocument ErrorDocument `xml:"ErrorDocument"` // The error page
  205. }
  206. // IndexDocument defines the index page info
  207. type IndexDocument struct {
  208. XMLName xml.Name `xml:"IndexDocument"`
  209. Suffix string `xml:"Suffix"` // The file name for the index page
  210. }
  211. // ErrorDocument defines the 404 error page info
  212. type ErrorDocument struct {
  213. XMLName xml.Name `xml:"ErrorDocument"`
  214. Key string `xml:"Key"` // 404 error file name
  215. }
  216. // GetBucketWebsiteResult defines the result from GetBucketWebsite request.
  217. type GetBucketWebsiteResult WebsiteXML
  218. // CORSXML defines CORS configuration
  219. type CORSXML struct {
  220. XMLName xml.Name `xml:"CORSConfiguration"`
  221. CORSRules []CORSRule `xml:"CORSRule"` // CORS rules
  222. }
  223. // CORSRule defines CORS rules
  224. type CORSRule struct {
  225. XMLName xml.Name `xml:"CORSRule"`
  226. AllowedOrigin []string `xml:"AllowedOrigin"` // Allowed origins. By default it's wildcard '*'
  227. AllowedMethod []string `xml:"AllowedMethod"` // Allowed methods
  228. AllowedHeader []string `xml:"AllowedHeader"` // Allowed headers
  229. ExposeHeader []string `xml:"ExposeHeader"` // Allowed response headers
  230. MaxAgeSeconds int `xml:"MaxAgeSeconds"` // Max cache ages in seconds
  231. }
  232. // GetBucketCORSResult defines the result from GetBucketCORS request.
  233. type GetBucketCORSResult CORSXML
  234. // GetBucketInfoResult defines the result from GetBucketInfo request.
  235. type GetBucketInfoResult struct {
  236. XMLName xml.Name `xml:"BucketInfo"`
  237. BucketInfo BucketInfo `xml:"Bucket"`
  238. }
  239. // BucketInfo defines Bucket information
  240. type BucketInfo struct {
  241. XMLName xml.Name `xml:"Bucket"`
  242. Name string `xml:"Name"` // Bucket name
  243. Location string `xml:"Location"` // Bucket datacenter
  244. CreationDate time.Time `xml:"CreationDate"` // Bucket creation time
  245. ExtranetEndpoint string `xml:"ExtranetEndpoint"` // Bucket external endpoint
  246. IntranetEndpoint string `xml:"IntranetEndpoint"` // Bucket internal endpoint
  247. ACL string `xml:"AccessControlList>Grant"` // Bucket ACL
  248. Owner Owner `xml:"Owner"` // Bucket owner
  249. StorageClass string `xml:"StorageClass"` // Bucket storage class
  250. }
  251. // ListObjectsResult defines the result from ListObjects request
  252. type ListObjectsResult struct {
  253. XMLName xml.Name `xml:"ListBucketResult"`
  254. Prefix string `xml:"Prefix"` // The object prefix
  255. Marker string `xml:"Marker"` // The marker filter.
  256. MaxKeys int `xml:"MaxKeys"` // Max keys to return
  257. Delimiter string `xml:"Delimiter"` // The delimiter for grouping objects' name
  258. IsTruncated bool `xml:"IsTruncated"` // Flag indicates if all results are returned (when it's false)
  259. NextMarker string `xml:"NextMarker"` // The start point of the next query
  260. Objects []ObjectProperties `xml:"Contents"` // Object list
  261. CommonPrefixes []string `xml:"CommonPrefixes>Prefix"` // You can think of commonprefixes as "folders" whose names end with the delimiter
  262. }
  263. // ObjectProperties defines Objecct properties
  264. type ObjectProperties struct {
  265. XMLName xml.Name `xml:"Contents"`
  266. Key string `xml:"Key"` // Object key
  267. Type string `xml:"Type"` // Object type
  268. Size int64 `xml:"Size"` // Object size
  269. ETag string `xml:"ETag"` // Object ETag
  270. Owner Owner `xml:"Owner"` // Object owner information
  271. LastModified time.Time `xml:"LastModified"` // Object last modified time
  272. StorageClass string `xml:"StorageClass"` // Object storage class (Standard, IA, Archive)
  273. }
  274. // Owner defines Bucket/Object's owner
  275. type Owner struct {
  276. XMLName xml.Name `xml:"Owner"`
  277. ID string `xml:"ID"` // Owner ID
  278. DisplayName string `xml:"DisplayName"` // Owner's display name
  279. }
  280. // CopyObjectResult defines result object of CopyObject
  281. type CopyObjectResult struct {
  282. XMLName xml.Name `xml:"CopyObjectResult"`
  283. LastModified time.Time `xml:"LastModified"` // New object's last modified time.
  284. ETag string `xml:"ETag"` // New object's ETag
  285. }
  286. // GetObjectACLResult defines result of GetObjectACL request
  287. type GetObjectACLResult GetBucketACLResult
  288. type deleteXML struct {
  289. XMLName xml.Name `xml:"Delete"`
  290. Objects []DeleteObject `xml:"Object"` // Objects to delete
  291. Quiet bool `xml:"Quiet"` // Flag of quiet mode.
  292. }
  293. // DeleteObject defines the struct for deleting object
  294. type DeleteObject struct {
  295. XMLName xml.Name `xml:"Object"`
  296. Key string `xml:"Key"` // Object name
  297. }
  298. // DeleteObjectsResult defines result of DeleteObjects request
  299. type DeleteObjectsResult struct {
  300. XMLName xml.Name `xml:"DeleteResult"`
  301. DeletedObjects []string `xml:"Deleted>Key"` // Deleted object list
  302. }
  303. // InitiateMultipartUploadResult defines result of InitiateMultipartUpload request
  304. type InitiateMultipartUploadResult struct {
  305. XMLName xml.Name `xml:"InitiateMultipartUploadResult"`
  306. Bucket string `xml:"Bucket"` // Bucket name
  307. Key string `xml:"Key"` // Object name to upload
  308. UploadID string `xml:"UploadId"` // Generated UploadId
  309. }
  310. // UploadPart defines the upload/copy part
  311. type UploadPart struct {
  312. XMLName xml.Name `xml:"Part"`
  313. PartNumber int `xml:"PartNumber"` // Part number
  314. ETag string `xml:"ETag"` // ETag value of the part's data
  315. }
  316. type uploadParts []UploadPart
  317. func (slice uploadParts) Len() int {
  318. return len(slice)
  319. }
  320. func (slice uploadParts) Less(i, j int) bool {
  321. return slice[i].PartNumber < slice[j].PartNumber
  322. }
  323. func (slice uploadParts) Swap(i, j int) {
  324. slice[i], slice[j] = slice[j], slice[i]
  325. }
  326. // UploadPartCopyResult defines result object of multipart copy request.
  327. type UploadPartCopyResult struct {
  328. XMLName xml.Name `xml:"CopyPartResult"`
  329. LastModified time.Time `xml:"LastModified"` // Last modified time
  330. ETag string `xml:"ETag"` // ETag
  331. }
  332. type completeMultipartUploadXML struct {
  333. XMLName xml.Name `xml:"CompleteMultipartUpload"`
  334. Part []UploadPart `xml:"Part"`
  335. }
  336. // CompleteMultipartUploadResult defines result object of CompleteMultipartUploadRequest
  337. type CompleteMultipartUploadResult struct {
  338. XMLName xml.Name `xml:"CompleteMultipartUploadResult"`
  339. Location string `xml:"Location"` // Object URL
  340. Bucket string `xml:"Bucket"` // Bucket name
  341. ETag string `xml:"ETag"` // Object ETag
  342. Key string `xml:"Key"` // Object name
  343. }
  344. // ListUploadedPartsResult defines result object of ListUploadedParts
  345. type ListUploadedPartsResult struct {
  346. XMLName xml.Name `xml:"ListPartsResult"`
  347. Bucket string `xml:"Bucket"` // Bucket name
  348. Key string `xml:"Key"` // Object name
  349. UploadID string `xml:"UploadId"` // Upload ID
  350. NextPartNumberMarker string `xml:"NextPartNumberMarker"` // Next part number
  351. MaxParts int `xml:"MaxParts"` // Max parts count
  352. IsTruncated bool `xml:"IsTruncated"` // Flag indicates all entries returned.false: all entries returned.
  353. UploadedParts []UploadedPart `xml:"Part"` // Uploaded parts
  354. }
  355. // UploadedPart defines uploaded part
  356. type UploadedPart struct {
  357. XMLName xml.Name `xml:"Part"`
  358. PartNumber int `xml:"PartNumber"` // Part number
  359. LastModified time.Time `xml:"LastModified"` // Last modified time
  360. ETag string `xml:"ETag"` // ETag cache
  361. Size int `xml:"Size"` // Part size
  362. }
  363. // ListMultipartUploadResult defines result object of ListMultipartUpload
  364. type ListMultipartUploadResult struct {
  365. XMLName xml.Name `xml:"ListMultipartUploadsResult"`
  366. Bucket string `xml:"Bucket"` // Bucket name
  367. Delimiter string `xml:"Delimiter"` // Delimiter for grouping object.
  368. Prefix string `xml:"Prefix"` // Object prefix
  369. KeyMarker string `xml:"KeyMarker"` // Object key marker
  370. UploadIDMarker string `xml:"UploadIdMarker"` // UploadId marker
  371. NextKeyMarker string `xml:"NextKeyMarker"` // Next key marker, if not all entries returned.
  372. NextUploadIDMarker string `xml:"NextUploadIdMarker"` // Next uploadId marker, if not all entries returned.
  373. MaxUploads int `xml:"MaxUploads"` // Max uploads to return
  374. IsTruncated bool `xml:"IsTruncated"` // Flag indicates all entries are returned.
  375. Uploads []UncompletedUpload `xml:"Upload"` // Ongoing uploads (not completed, not aborted)
  376. CommonPrefixes []string `xml:"CommonPrefixes>Prefix"` // Common prefixes list.
  377. }
  378. // UncompletedUpload structure wraps an uncompleted upload task
  379. type UncompletedUpload struct {
  380. XMLName xml.Name `xml:"Upload"`
  381. Key string `xml:"Key"` // Object name
  382. UploadID string `xml:"UploadId"` // The UploadId
  383. Initiated time.Time `xml:"Initiated"` // Initialization time in the format such as 2012-02-23T04:18:23.000Z
  384. }
  385. // ProcessObjectResult defines result object of ProcessObject
  386. type ProcessObjectResult struct {
  387. Bucket string `json:"bucket"`
  388. FileSize int `json:"fileSize"`
  389. Object string `json:"object"`
  390. Status string `json:"status"`
  391. }
  392. // decodeDeleteObjectsResult decodes deleting objects result in URL encoding
  393. func decodeDeleteObjectsResult(result *DeleteObjectsResult) error {
  394. var err error
  395. for i := 0; i < len(result.DeletedObjects); i++ {
  396. result.DeletedObjects[i], err = url.QueryUnescape(result.DeletedObjects[i])
  397. if err != nil {
  398. return err
  399. }
  400. }
  401. return nil
  402. }
  403. // decodeListObjectsResult decodes list objects result in URL encoding
  404. func decodeListObjectsResult(result *ListObjectsResult) error {
  405. var err error
  406. result.Prefix, err = url.QueryUnescape(result.Prefix)
  407. if err != nil {
  408. return err
  409. }
  410. result.Marker, err = url.QueryUnescape(result.Marker)
  411. if err != nil {
  412. return err
  413. }
  414. result.Delimiter, err = url.QueryUnescape(result.Delimiter)
  415. if err != nil {
  416. return err
  417. }
  418. result.NextMarker, err = url.QueryUnescape(result.NextMarker)
  419. if err != nil {
  420. return err
  421. }
  422. for i := 0; i < len(result.Objects); i++ {
  423. result.Objects[i].Key, err = url.QueryUnescape(result.Objects[i].Key)
  424. if err != nil {
  425. return err
  426. }
  427. }
  428. for i := 0; i < len(result.CommonPrefixes); i++ {
  429. result.CommonPrefixes[i], err = url.QueryUnescape(result.CommonPrefixes[i])
  430. if err != nil {
  431. return err
  432. }
  433. }
  434. return nil
  435. }
  436. // decodeListUploadedPartsResult decodes
  437. func decodeListUploadedPartsResult(result *ListUploadedPartsResult) error {
  438. var err error
  439. result.Key, err = url.QueryUnescape(result.Key)
  440. if err != nil {
  441. return err
  442. }
  443. return nil
  444. }
  445. // decodeListMultipartUploadResult decodes list multipart upload result in URL encoding
  446. func decodeListMultipartUploadResult(result *ListMultipartUploadResult) error {
  447. var err error
  448. result.Prefix, err = url.QueryUnescape(result.Prefix)
  449. if err != nil {
  450. return err
  451. }
  452. result.Delimiter, err = url.QueryUnescape(result.Delimiter)
  453. if err != nil {
  454. return err
  455. }
  456. result.KeyMarker, err = url.QueryUnescape(result.KeyMarker)
  457. if err != nil {
  458. return err
  459. }
  460. result.NextKeyMarker, err = url.QueryUnescape(result.NextKeyMarker)
  461. if err != nil {
  462. return err
  463. }
  464. for i := 0; i < len(result.Uploads); i++ {
  465. result.Uploads[i].Key, err = url.QueryUnescape(result.Uploads[i].Key)
  466. if err != nil {
  467. return err
  468. }
  469. }
  470. for i := 0; i < len(result.CommonPrefixes); i++ {
  471. result.CommonPrefixes[i], err = url.QueryUnescape(result.CommonPrefixes[i])
  472. if err != nil {
  473. return err
  474. }
  475. }
  476. return nil
  477. }
  478. // createBucketConfiguration defines the configuration for creating a bucket.
  479. type createBucketConfiguration struct {
  480. XMLName xml.Name `xml:"CreateBucketConfiguration"`
  481. StorageClass StorageClassType `xml:"StorageClass,omitempty"`
  482. }
  483. // LiveChannelConfiguration defines the configuration for live-channel
  484. type LiveChannelConfiguration struct {
  485. XMLName xml.Name `xml:"LiveChannelConfiguration"`
  486. Description string `xml:"Description,omitempty"` //Description of live-channel, up to 128 bytes
  487. Status string `xml:"Status,omitempty"` //Specify the status of livechannel
  488. Target LiveChannelTarget `xml:"Target"` //target configuration of live-channel
  489. // use point instead of struct to avoid omit empty snapshot
  490. Snapshot *LiveChannelSnapshot `xml:"Snapshot,omitempty"` //snapshot configuration of live-channel
  491. }
  492. // LiveChannelTarget target configuration of live-channel
  493. type LiveChannelTarget struct {
  494. XMLName xml.Name `xml:"Target"`
  495. Type string `xml:"Type"` //the type of object, only supports HLS
  496. FragDuration int `xml:"FragDuration,omitempty"` //the length of each ts object (in seconds), in the range [1,100]
  497. FragCount int `xml:"FragCount,omitempty"` //the number of ts objects in the m3u8 object, in the range of [1,100]
  498. PlaylistName string `xml:"PlaylistName,omitempty"` //the name of m3u8 object, which must end with ".m3u8" and the length range is [6,128]
  499. }
  500. // LiveChannelSnapshot snapshot configuration of live-channel
  501. type LiveChannelSnapshot struct {
  502. XMLName xml.Name `xml:"Snapshot"`
  503. 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.
  504. DestBucket string `xml:"DestBucket,omitempty"` //Bucket the snapshots will be written to. should be the same owner as the source bucket.
  505. NotifyTopic string `xml:"NotifyTopic,omitempty"` //Topics of MNS for notifying users of high frequency screenshot operation results
  506. Interval int `xml:"Interval,omitempty"` //interval of snapshots, threre is no snapshot if no I-frame during the interval time
  507. }
  508. // CreateLiveChannelResult the result of crete live-channel
  509. type CreateLiveChannelResult struct {
  510. XMLName xml.Name `xml:"CreateLiveChannelResult"`
  511. PublishUrls []string `xml:"PublishUrls>Url"` //push urls list
  512. PlayUrls []string `xml:"PlayUrls>Url"` //play urls list
  513. }
  514. // LiveChannelStat the result of get live-channel state
  515. type LiveChannelStat struct {
  516. XMLName xml.Name `xml:"LiveChannelStat"`
  517. Status string `xml:"Status"` //Current push status of live-channel: Disabled,Live,Idle
  518. ConnectedTime time.Time `xml:"ConnectedTime"` //The time when the client starts pushing, format: ISO8601
  519. RemoteAddr string `xml:"RemoteAddr"` //The ip address of the client
  520. Video LiveChannelVideo `xml:"Video"` //Video stream information
  521. Audio LiveChannelAudio `xml:"Audio"` //Audio stream information
  522. }
  523. // LiveChannelVideo video stream information
  524. type LiveChannelVideo struct {
  525. XMLName xml.Name `xml:"Video"`
  526. Width int `xml:"Width"` //Width (unit: pixels)
  527. Height int `xml:"Height"` //Height (unit: pixels)
  528. FrameRate int `xml:"FrameRate"` //FramRate
  529. Bandwidth int `xml:"Bandwidth"` //Bandwidth (unit: B/s)
  530. }
  531. // LiveChannelAudio audio stream information
  532. type LiveChannelAudio struct {
  533. XMLName xml.Name `xml:"Audio"`
  534. SampleRate int `xml:"SampleRate"` //SampleRate
  535. Bandwidth int `xml:"Bandwidth"` //Bandwidth (unit: B/s)
  536. Codec string `xml:"Codec"` //Encoding forma
  537. }
  538. // LiveChannelHistory the result of GetLiveChannelHistory, at most return up to lastest 10 push records
  539. type LiveChannelHistory struct {
  540. XMLName xml.Name `xml:"LiveChannelHistory"`
  541. Record []LiveRecord `xml:"LiveRecord"` //push records list
  542. }
  543. // LiveRecord push recode
  544. type LiveRecord struct {
  545. XMLName xml.Name `xml:"LiveRecord"`
  546. StartTime time.Time `xml:"StartTime"` //StartTime, format: ISO8601
  547. EndTime time.Time `xml:"EndTime"` //EndTime, format: ISO8601
  548. RemoteAddr string `xml:"RemoteAddr"` //The ip address of remote client
  549. }
  550. // ListLiveChannelResult the result of ListLiveChannel
  551. type ListLiveChannelResult struct {
  552. XMLName xml.Name `xml:"ListLiveChannelResult"`
  553. Prefix string `xml:"Prefix"` //Filter by the name start with the value of "Prefix"
  554. Marker string `xml:"Marker"` //cursor from which starting list
  555. MaxKeys int `xml:"MaxKeys"` //The maximum count returned. the default value is 100. it cannot be greater than 1000.
  556. IsTruncated bool `xml:"IsTruncated"` //Indicates whether all results have been returned, "true" indicates partial results returned while "false" indicates all results have been returned
  557. NextMarker string `xml:"NextMarker"` //NextMarker indicate the Marker value of the next request
  558. LiveChannel []LiveChannelInfo `xml:"LiveChannel"` //The infomation of live-channel
  559. }
  560. // LiveChannelInfo the infomation of live-channel
  561. type LiveChannelInfo struct {
  562. XMLName xml.Name `xml:"LiveChannel"`
  563. Name string `xml:"Name"` //The name of live-channel
  564. Description string `xml:"Description"` //Description of live-channel
  565. Status string `xml:"Status"` //Status: disabled or enabled
  566. LastModified time.Time `xml:"LastModified"` //Last modification time, format: ISO8601
  567. PublishUrls []string `xml:"PublishUrls>Url"` //push urls list
  568. PlayUrls []string `xml:"PlayUrls>Url"` //play urls list
  569. }