type.go 26 KB

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