type.go 26 KB

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