type.go 27 KB

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