type.go 27 KB

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