OSDN Git Service

Create ossClient.go (#574)
[bytom/vapor.git] / vendor / github.com / aliyun / aliyun-oss-go-sdk / oss / type.go
1 package oss
2
3 import (
4         "encoding/base64"
5         "encoding/xml"
6         "fmt"
7         "net/url"
8         "time"
9 )
10
11 // ListBucketsResult defines the result object from ListBuckets request
12 type ListBucketsResult struct {
13         XMLName     xml.Name           `xml:"ListAllMyBucketsResult"`
14         Prefix      string             `xml:"Prefix"`         // The prefix in this query
15         Marker      string             `xml:"Marker"`         // The marker filter
16         MaxKeys     int                `xml:"MaxKeys"`        // The max entry count to return. This information is returned when IsTruncated is true.
17         IsTruncated bool               `xml:"IsTruncated"`    // Flag true means there's remaining buckets to return.
18         NextMarker  string             `xml:"NextMarker"`     // The marker filter for the next list call
19         Owner       Owner              `xml:"Owner"`          // The owner information
20         Buckets     []BucketProperties `xml:"Buckets>Bucket"` // The bucket list
21 }
22
23 // BucketProperties defines bucket properties
24 type BucketProperties struct {
25         XMLName      xml.Name  `xml:"Bucket"`
26         Name         string    `xml:"Name"`         // Bucket name
27         Location     string    `xml:"Location"`     // Bucket datacenter
28         CreationDate time.Time `xml:"CreationDate"` // Bucket create time
29         StorageClass string    `xml:"StorageClass"` // Bucket storage class
30 }
31
32 // GetBucketACLResult defines GetBucketACL request's result
33 type GetBucketACLResult struct {
34         XMLName xml.Name `xml:"AccessControlPolicy"`
35         ACL     string   `xml:"AccessControlList>Grant"` // Bucket ACL
36         Owner   Owner    `xml:"Owner"`                   // Bucket owner
37 }
38
39 // LifecycleConfiguration is the Bucket Lifecycle configuration
40 type LifecycleConfiguration struct {
41         XMLName xml.Name        `xml:"LifecycleConfiguration"`
42         Rules   []LifecycleRule `xml:"Rule"`
43 }
44
45 // LifecycleRule defines Lifecycle rules
46 type LifecycleRule struct {
47         XMLName              xml.Name                       `xml:"Rule"`
48         ID                   string                         `xml:"ID,omitempty"`                   // The rule ID
49         Prefix               string                         `xml:"Prefix"`                         // The object key prefix
50         Status               string                         `xml:"Status"`                         // The rule status (enabled or not)
51         Tags                 []Tag                          `xml:"Tag,omitempty"`                  // the tags property
52         Expiration           *LifecycleExpiration           `xml:"Expiration,omitempty"`           // The expiration property
53         Transitions          []LifecycleTransition          `xml:"Transition,omitempty"`           // The transition property
54         AbortMultipartUpload *LifecycleAbortMultipartUpload `xml:"AbortMultipartUpload,omitempty"` // The AbortMultipartUpload property
55         NonVersionExpiration *LifecycleVersionExpiration    `xml:"NoncurrentVersionExpiration,omitempty"`
56         // Deprecated: Use NonVersionTransitions instead.
57         NonVersionTransition  *LifecycleVersionTransition  `xml:"-"` // NonVersionTransition is not suggested to use
58         NonVersionTransitions []LifecycleVersionTransition `xml:"NoncurrentVersionTransition,omitempty"`
59 }
60
61 // LifecycleExpiration defines the rule's expiration property
62 type LifecycleExpiration struct {
63         XMLName                   xml.Name `xml:"Expiration"`
64         Days                      int      `xml:"Days,omitempty"`                      // Relative expiration time: The expiration time in days after the last modified time
65         Date                      string   `xml:"Date,omitempty"`                      // Absolute expiration time: The expiration time in date, not recommended
66         CreatedBeforeDate         string   `xml:"CreatedBeforeDate,omitempty"`         // objects created before the date will be expired
67         ExpiredObjectDeleteMarker *bool    `xml:"ExpiredObjectDeleteMarker,omitempty"` // Specifies whether the expired delete tag is automatically deleted
68 }
69
70 // LifecycleTransition defines the rule's transition propery
71 type LifecycleTransition struct {
72         XMLName           xml.Name         `xml:"Transition"`
73         Days              int              `xml:"Days,omitempty"`              // Relative transition time: The transition time in days after the last modified time
74         CreatedBeforeDate string           `xml:"CreatedBeforeDate,omitempty"` // objects created before the date will be expired
75         StorageClass      StorageClassType `xml:"StorageClass,omitempty"`      // Specifies the target storage type
76 }
77
78 // LifecycleAbortMultipartUpload defines the rule's abort multipart upload propery
79 type LifecycleAbortMultipartUpload struct {
80         XMLName           xml.Name `xml:"AbortMultipartUpload"`
81         Days              int      `xml:"Days,omitempty"`              // Relative expiration time: The expiration time in days after the last modified time
82         CreatedBeforeDate string   `xml:"CreatedBeforeDate,omitempty"` // objects created before the date will be expired
83 }
84
85 // LifecycleVersionExpiration defines the rule's NoncurrentVersionExpiration propery
86 type LifecycleVersionExpiration struct {
87         XMLName        xml.Name `xml:"NoncurrentVersionExpiration"`
88         NoncurrentDays int      `xml:"NoncurrentDays,omitempty"` // How many days after the Object becomes a non-current version
89 }
90
91 // LifecycleVersionTransition defines the rule's NoncurrentVersionTransition propery
92 type LifecycleVersionTransition struct {
93         XMLName        xml.Name         `xml:"NoncurrentVersionTransition"`
94         NoncurrentDays int              `xml:"NoncurrentDays,omitempty"` // How many days after the Object becomes a non-current version
95         StorageClass   StorageClassType `xml:"StorageClass,omitempty"`
96 }
97
98 const iso8601DateFormat = "2006-01-02T15:04:05.000Z"
99
100 // BuildLifecycleRuleByDays builds a lifecycle rule objects will expiration in days after the last modified time
101 func BuildLifecycleRuleByDays(id, prefix string, status bool, days int) LifecycleRule {
102         var statusStr = "Enabled"
103         if !status {
104                 statusStr = "Disabled"
105         }
106         return LifecycleRule{ID: id, Prefix: prefix, Status: statusStr,
107                 Expiration: &LifecycleExpiration{Days: days}}
108 }
109
110 // BuildLifecycleRuleByDate builds a lifecycle rule objects will expiration in specified date
111 func BuildLifecycleRuleByDate(id, prefix string, status bool, year, month, day int) LifecycleRule {
112         var statusStr = "Enabled"
113         if !status {
114                 statusStr = "Disabled"
115         }
116         date := time.Date(year, time.Month(month), day, 0, 0, 0, 0, time.UTC).Format(iso8601DateFormat)
117         return LifecycleRule{ID: id, Prefix: prefix, Status: statusStr,
118                 Expiration: &LifecycleExpiration{Date: date}}
119 }
120
121 // ValidateLifecycleRule Determine if a lifecycle rule is valid, if it is invalid, it will return an error.
122 func verifyLifecycleRules(rules []LifecycleRule) error {
123         if len(rules) == 0 {
124                 return fmt.Errorf("invalid rules, the length of rules is zero")
125         }
126         for k, rule := range rules {
127                 if rule.Status != "Enabled" && rule.Status != "Disabled" {
128                         return fmt.Errorf("invalid rule, the value of status must be Enabled or Disabled")
129                 }
130
131                 abortMPU := rule.AbortMultipartUpload
132                 if abortMPU != nil {
133                         if (abortMPU.Days != 0 && abortMPU.CreatedBeforeDate != "") || (abortMPU.Days == 0 && abortMPU.CreatedBeforeDate == "") {
134                                 return fmt.Errorf("invalid abort multipart upload lifecycle, must be set one of CreatedBeforeDate and Days")
135                         }
136                 }
137
138                 transitions := rule.Transitions
139                 if len(transitions) > 0 {
140                         for _, transition := range transitions {
141                                 if (transition.Days != 0 && transition.CreatedBeforeDate != "") || (transition.Days == 0 && transition.CreatedBeforeDate == "") {
142                                         return fmt.Errorf("invalid transition lifecycle, must be set one of CreatedBeforeDate and Days")
143                                 }
144                         }
145                 }
146
147                 // NonVersionTransition is not suggested to use
148                 // to keep compatible
149                 if rule.NonVersionTransition != nil && len(rule.NonVersionTransitions) > 0 {
150                         return fmt.Errorf("NonVersionTransition and NonVersionTransitions cannot both have values")
151                 } else if rule.NonVersionTransition != nil {
152                         rules[k].NonVersionTransitions = append(rules[k].NonVersionTransitions, *rule.NonVersionTransition)
153                 }
154         }
155
156         return nil
157 }
158
159 // GetBucketLifecycleResult defines GetBucketLifecycle's result object
160 type GetBucketLifecycleResult LifecycleConfiguration
161
162 // RefererXML defines Referer configuration
163 type RefererXML struct {
164         XMLName           xml.Name `xml:"RefererConfiguration"`
165         AllowEmptyReferer bool     `xml:"AllowEmptyReferer"`   // Allow empty referrer
166         RefererList       []string `xml:"RefererList>Referer"` // Referer whitelist
167 }
168
169 // GetBucketRefererResult defines result object for GetBucketReferer request
170 type GetBucketRefererResult RefererXML
171
172 // LoggingXML defines logging configuration
173 type LoggingXML struct {
174         XMLName        xml.Name       `xml:"BucketLoggingStatus"`
175         LoggingEnabled LoggingEnabled `xml:"LoggingEnabled"` // The logging configuration information
176 }
177
178 type loggingXMLEmpty struct {
179         XMLName xml.Name `xml:"BucketLoggingStatus"`
180 }
181
182 // LoggingEnabled defines the logging configuration information
183 type LoggingEnabled struct {
184         XMLName      xml.Name `xml:"LoggingEnabled"`
185         TargetBucket string   `xml:"TargetBucket"` // The bucket name for storing the log files
186         TargetPrefix string   `xml:"TargetPrefix"` // The log file prefix
187 }
188
189 // GetBucketLoggingResult defines the result from GetBucketLogging request
190 type GetBucketLoggingResult LoggingXML
191
192 // WebsiteXML defines Website configuration
193 type WebsiteXML struct {
194         XMLName       xml.Name      `xml:"WebsiteConfiguration"`
195         IndexDocument IndexDocument `xml:"IndexDocument,omitempty"`            // The index page
196         ErrorDocument ErrorDocument `xml:"ErrorDocument,omitempty"`            // The error page
197         RoutingRules  []RoutingRule `xml:"RoutingRules>RoutingRule,omitempty"` // The routing Rule list
198 }
199
200 // IndexDocument defines the index page info
201 type IndexDocument struct {
202         XMLName xml.Name `xml:"IndexDocument"`
203         Suffix  string   `xml:"Suffix"` // The file name for the index page
204 }
205
206 // ErrorDocument defines the 404 error page info
207 type ErrorDocument struct {
208         XMLName xml.Name `xml:"ErrorDocument"`
209         Key     string   `xml:"Key"` // 404 error file name
210 }
211
212 // RoutingRule defines the routing rules
213 type RoutingRule struct {
214         XMLName    xml.Name  `xml:"RoutingRule"`
215         RuleNumber int       `xml:"RuleNumber,omitempty"` // The routing number
216         Condition  Condition `xml:"Condition,omitempty"`  // The routing condition
217         Redirect   Redirect  `xml:"Redirect,omitempty"`   // The routing redirect
218
219 }
220
221 // Condition defines codition in the RoutingRule
222 type Condition struct {
223         XMLName                     xml.Name        `xml:"Condition"`
224         KeyPrefixEquals             string          `xml:"KeyPrefixEquals,omitempty"`             // Matching objcet prefix
225         HTTPErrorCodeReturnedEquals int             `xml:"HttpErrorCodeReturnedEquals,omitempty"` // The rule is for Accessing to the specified object
226         IncludeHeader               []IncludeHeader `xml:"IncludeHeader"`                         // The rule is for request which include header
227 }
228
229 // IncludeHeader defines includeHeader in the RoutingRule's Condition
230 type IncludeHeader struct {
231         XMLName xml.Name `xml:"IncludeHeader"`
232         Key     string   `xml:"Key,omitempty"`    // The Include header key
233         Equals  string   `xml:"Equals,omitempty"` // The Include header value
234 }
235
236 // Redirect defines redirect in the RoutingRule
237 type Redirect struct {
238         XMLName               xml.Name      `xml:"Redirect"`
239         RedirectType          string        `xml:"RedirectType,omitempty"`         // The redirect type, it have Mirror,External,Internal,AliCDN
240         PassQueryString       *bool         `xml:"PassQueryString"`                // Whether to send the specified request's parameters, true or false
241         MirrorURL             string        `xml:"MirrorURL,omitempty"`            // Mirror of the website address back to the source.
242         MirrorPassQueryString *bool         `xml:"MirrorPassQueryString"`          // To Mirror of the website Whether to send the specified request's parameters, true or false
243         MirrorFollowRedirect  *bool         `xml:"MirrorFollowRedirect"`           // Redirect the location, if the mirror return 3XX
244         MirrorCheckMd5        *bool         `xml:"MirrorCheckMd5"`                 // Check the mirror is MD5.
245         MirrorHeaders         MirrorHeaders `xml:"MirrorHeaders,omitempty"`        // Mirror headers
246         Protocol              string        `xml:"Protocol,omitempty"`             // The redirect Protocol
247         HostName              string        `xml:"HostName,omitempty"`             // The redirect HostName
248         ReplaceKeyPrefixWith  string        `xml:"ReplaceKeyPrefixWith,omitempty"` // object name'Prefix replace the value
249         HttpRedirectCode      int           `xml:"HttpRedirectCode,omitempty"`     // THe redirect http code
250         ReplaceKeyWith        string        `xml:"ReplaceKeyWith,omitempty"`       // object name replace the value
251 }
252
253 // MirrorHeaders defines MirrorHeaders in the Redirect
254 type MirrorHeaders struct {
255         XMLName xml.Name          `xml:"MirrorHeaders"`
256         PassAll *bool             `xml:"PassAll"` // Penetrating all of headers to source website.
257         Pass    []string          `xml:"Pass"`    // Penetrating some of headers to source website.
258         Remove  []string          `xml:"Remove"`  // Prohibit passthrough some of headers to source website
259         Set     []MirrorHeaderSet `xml:"Set"`     // Setting some of headers send to source website
260 }
261
262 // MirrorHeaderSet defines Set for Redirect's MirrorHeaders
263 type MirrorHeaderSet struct {
264         XMLName xml.Name `xml:"Set"`
265         Key     string   `xml:"Key,omitempty"`   // The mirror header key
266         Value   string   `xml:"Value,omitempty"` // The mirror header value
267 }
268
269 // GetBucketWebsiteResult defines the result from GetBucketWebsite request.
270 type GetBucketWebsiteResult WebsiteXML
271
272 // CORSXML defines CORS configuration
273 type CORSXML struct {
274         XMLName   xml.Name   `xml:"CORSConfiguration"`
275         CORSRules []CORSRule `xml:"CORSRule"` // CORS rules
276 }
277
278 // CORSRule defines CORS rules
279 type CORSRule struct {
280         XMLName       xml.Name `xml:"CORSRule"`
281         AllowedOrigin []string `xml:"AllowedOrigin"` // Allowed origins. By default it's wildcard '*'
282         AllowedMethod []string `xml:"AllowedMethod"` // Allowed methods
283         AllowedHeader []string `xml:"AllowedHeader"` // Allowed headers
284         ExposeHeader  []string `xml:"ExposeHeader"`  // Allowed response headers
285         MaxAgeSeconds int      `xml:"MaxAgeSeconds"` // Max cache ages in seconds
286 }
287
288 // GetBucketCORSResult defines the result from GetBucketCORS request.
289 type GetBucketCORSResult CORSXML
290
291 // GetBucketInfoResult defines the result from GetBucketInfo request.
292 type GetBucketInfoResult struct {
293         XMLName    xml.Name   `xml:"BucketInfo"`
294         BucketInfo BucketInfo `xml:"Bucket"`
295 }
296
297 // BucketInfo defines Bucket information
298 type BucketInfo struct {
299         XMLName          xml.Name  `xml:"Bucket"`
300         Name             string    `xml:"Name"`                     // Bucket name
301         Location         string    `xml:"Location"`                 // Bucket datacenter
302         CreationDate     time.Time `xml:"CreationDate"`             // Bucket creation time
303         ExtranetEndpoint string    `xml:"ExtranetEndpoint"`         // Bucket external endpoint
304         IntranetEndpoint string    `xml:"IntranetEndpoint"`         // Bucket internal endpoint
305         ACL              string    `xml:"AccessControlList>Grant"`  // Bucket ACL
306         RedundancyType   string    `xml:"DataRedundancyType"`       // Bucket DataRedundancyType
307         Owner            Owner     `xml:"Owner"`                    // Bucket owner
308         StorageClass     string    `xml:"StorageClass"`             // Bucket storage class
309         SseRule          SSERule   `xml:"ServerSideEncryptionRule"` // Bucket ServerSideEncryptionRule
310         Versioning       string    `xml:"Versioning"`               // Bucket Versioning
311 }
312
313 type SSERule struct {
314         XMLName           xml.Name `xml:"ServerSideEncryptionRule"`    // Bucket ServerSideEncryptionRule
315         KMSMasterKeyID    string   `xml:"KMSMasterKeyID,omitempty"`    // Bucket KMSMasterKeyID
316         SSEAlgorithm      string   `xml:"SSEAlgorithm,omitempty"`      // Bucket SSEAlgorithm
317         KMSDataEncryption string   `xml:"KMSDataEncryption,omitempty"` //Bucket KMSDataEncryption
318 }
319
320 // ListObjectsResult defines the result from ListObjects request
321 type ListObjectsResult struct {
322         XMLName        xml.Name           `xml:"ListBucketResult"`
323         Prefix         string             `xml:"Prefix"`                // The object prefix
324         Marker         string             `xml:"Marker"`                // The marker filter.
325         MaxKeys        int                `xml:"MaxKeys"`               // Max keys to return
326         Delimiter      string             `xml:"Delimiter"`             // The delimiter for grouping objects' name
327         IsTruncated    bool               `xml:"IsTruncated"`           // Flag indicates if all results are returned (when it's false)
328         NextMarker     string             `xml:"NextMarker"`            // The start point of the next query
329         Objects        []ObjectProperties `xml:"Contents"`              // Object list
330         CommonPrefixes []string           `xml:"CommonPrefixes>Prefix"` // You can think of commonprefixes as "folders" whose names end with the delimiter
331 }
332
333 // ObjectProperties defines Objecct properties
334 type ObjectProperties struct {
335         XMLName      xml.Name  `xml:"Contents"`
336         Key          string    `xml:"Key"`          // Object key
337         Type         string    `xml:"Type"`         // Object type
338         Size         int64     `xml:"Size"`         // Object size
339         ETag         string    `xml:"ETag"`         // Object ETag
340         Owner        Owner     `xml:"Owner"`        // Object owner information
341         LastModified time.Time `xml:"LastModified"` // Object last modified time
342         StorageClass string    `xml:"StorageClass"` // Object storage class (Standard, IA, Archive)
343 }
344
345 // ListObjectsResultV2 defines the result from ListObjectsV2 request
346 type ListObjectsResultV2 struct {
347         XMLName               xml.Name           `xml:"ListBucketResult"`
348         Prefix                string             `xml:"Prefix"`                // The object prefix
349         StartAfter            string             `xml:"StartAfter"`            // the input StartAfter
350         ContinuationToken     string             `xml:"ContinuationToken"`     // the input ContinuationToken
351         MaxKeys               int                `xml:"MaxKeys"`               // Max keys to return
352         Delimiter             string             `xml:"Delimiter"`             // The delimiter for grouping objects' name
353         IsTruncated           bool               `xml:"IsTruncated"`           // Flag indicates if all results are returned (when it's false)
354         NextContinuationToken string             `xml:"NextContinuationToken"` // The start point of the next NextContinuationToken
355         Objects               []ObjectProperties `xml:"Contents"`              // Object list
356         CommonPrefixes        []string           `xml:"CommonPrefixes>Prefix"` // You can think of commonprefixes as "folders" whose names end with the delimiter
357 }
358
359 // ListObjectVersionsResult defines the result from ListObjectVersions request
360 type ListObjectVersionsResult struct {
361         XMLName             xml.Name                       `xml:"ListVersionsResult"`
362         Name                string                         `xml:"Name"`                  // The Bucket Name
363         Owner               Owner                          `xml:"Owner"`                 // The owner of bucket
364         Prefix              string                         `xml:"Prefix"`                // The object prefix
365         KeyMarker           string                         `xml:"KeyMarker"`             // The start marker filter.
366         VersionIdMarker     string                         `xml:"VersionIdMarker"`       // The start VersionIdMarker filter.
367         MaxKeys             int                            `xml:"MaxKeys"`               // Max keys to return
368         Delimiter           string                         `xml:"Delimiter"`             // The delimiter for grouping objects' name
369         IsTruncated         bool                           `xml:"IsTruncated"`           // Flag indicates if all results are returned (when it's false)
370         NextKeyMarker       string                         `xml:"NextKeyMarker"`         // The start point of the next query
371         NextVersionIdMarker string                         `xml:"NextVersionIdMarker"`   // The start point of the next query
372         CommonPrefixes      []string                       `xml:"CommonPrefixes>Prefix"` // You can think of commonprefixes as "folders" whose names end with the delimiter
373         ObjectDeleteMarkers []ObjectDeleteMarkerProperties `xml:"DeleteMarker"`          // DeleteMarker list
374         ObjectVersions      []ObjectVersionProperties      `xml:"Version"`               // version list
375 }
376
377 type ObjectDeleteMarkerProperties struct {
378         XMLName      xml.Name  `xml:"DeleteMarker"`
379         Key          string    `xml:"Key"`          // The Object Key
380         VersionId    string    `xml:"VersionId"`    // The Object VersionId
381         IsLatest     bool      `xml:"IsLatest"`     // is current version or not
382         LastModified time.Time `xml:"LastModified"` // Object last modified time
383         Owner        Owner     `xml:"Owner"`        // bucket owner element
384 }
385
386 type ObjectVersionProperties struct {
387         XMLName      xml.Name  `xml:"Version"`
388         Key          string    `xml:"Key"`          // The Object Key
389         VersionId    string    `xml:"VersionId"`    // The Object VersionId
390         IsLatest     bool      `xml:"IsLatest"`     // is latest version or not
391         LastModified time.Time `xml:"LastModified"` // Object last modified time
392         Type         string    `xml:"Type"`         // Object type
393         Size         int64     `xml:"Size"`         // Object size
394         ETag         string    `xml:"ETag"`         // Object ETag
395         StorageClass string    `xml:"StorageClass"` // Object storage class (Standard, IA, Archive)
396         Owner        Owner     `xml:"Owner"`        // bucket owner element
397 }
398
399 // Owner defines Bucket/Object's owner
400 type Owner struct {
401         XMLName     xml.Name `xml:"Owner"`
402         ID          string   `xml:"ID"`          // Owner ID
403         DisplayName string   `xml:"DisplayName"` // Owner's display name
404 }
405
406 // CopyObjectResult defines result object of CopyObject
407 type CopyObjectResult struct {
408         XMLName      xml.Name  `xml:"CopyObjectResult"`
409         LastModified time.Time `xml:"LastModified"` // New object's last modified time.
410         ETag         string    `xml:"ETag"`         // New object's ETag
411 }
412
413 // GetObjectACLResult defines result of GetObjectACL request
414 type GetObjectACLResult GetBucketACLResult
415
416 type deleteXML struct {
417         XMLName xml.Name       `xml:"Delete"`
418         Objects []DeleteObject `xml:"Object"` // Objects to delete
419         Quiet   bool           `xml:"Quiet"`  // Flag of quiet mode.
420 }
421
422 // DeleteObject defines the struct for deleting object
423 type DeleteObject struct {
424         XMLName   xml.Name `xml:"Object"`
425         Key       string   `xml:"Key"`                 // Object name
426         VersionId string   `xml:"VersionId,omitempty"` // Object VersionId
427 }
428
429 // DeleteObjectsResult defines result of DeleteObjects request
430 type DeleteObjectsResult struct {
431         XMLName        xml.Name
432         DeletedObjects []string // Deleted object key list
433 }
434
435 // DeleteObjectsResult_inner defines result of DeleteObjects request
436 type DeleteObjectVersionsResult struct {
437         XMLName              xml.Name         `xml:"DeleteResult"`
438         DeletedObjectsDetail []DeletedKeyInfo `xml:"Deleted"` // Deleted object detail info
439 }
440
441 // DeleteKeyInfo defines object delete info
442 type DeletedKeyInfo struct {
443         XMLName               xml.Name `xml:"Deleted"`
444         Key                   string   `xml:"Key"`                   // Object key
445         VersionId             string   `xml:"VersionId"`             // VersionId
446         DeleteMarker          bool     `xml:"DeleteMarker"`          // Object DeleteMarker
447         DeleteMarkerVersionId string   `xml:"DeleteMarkerVersionId"` // Object DeleteMarkerVersionId
448 }
449
450 // InitiateMultipartUploadResult defines result of InitiateMultipartUpload request
451 type InitiateMultipartUploadResult struct {
452         XMLName  xml.Name `xml:"InitiateMultipartUploadResult"`
453         Bucket   string   `xml:"Bucket"`   // Bucket name
454         Key      string   `xml:"Key"`      // Object name to upload
455         UploadID string   `xml:"UploadId"` // Generated UploadId
456 }
457
458 // UploadPart defines the upload/copy part
459 type UploadPart struct {
460         XMLName    xml.Name `xml:"Part"`
461         PartNumber int      `xml:"PartNumber"` // Part number
462         ETag       string   `xml:"ETag"`       // ETag value of the part's data
463 }
464
465 type UploadParts []UploadPart
466
467 func (slice UploadParts) Len() int {
468         return len(slice)
469 }
470
471 func (slice UploadParts) Less(i, j int) bool {
472         return slice[i].PartNumber < slice[j].PartNumber
473 }
474
475 func (slice UploadParts) Swap(i, j int) {
476         slice[i], slice[j] = slice[j], slice[i]
477 }
478
479 // UploadPartCopyResult defines result object of multipart copy request.
480 type UploadPartCopyResult struct {
481         XMLName      xml.Name  `xml:"CopyPartResult"`
482         LastModified time.Time `xml:"LastModified"` // Last modified time
483         ETag         string    `xml:"ETag"`         // ETag
484 }
485
486 type completeMultipartUploadXML struct {
487         XMLName xml.Name     `xml:"CompleteMultipartUpload"`
488         Part    []UploadPart `xml:"Part"`
489 }
490
491 // CompleteMultipartUploadResult defines result object of CompleteMultipartUploadRequest
492 type CompleteMultipartUploadResult struct {
493         XMLName  xml.Name `xml:"CompleteMultipartUploadResult"`
494         Location string   `xml:"Location"` // Object URL
495         Bucket   string   `xml:"Bucket"`   // Bucket name
496         ETag     string   `xml:"ETag"`     // Object ETag
497         Key      string   `xml:"Key"`      // Object name
498 }
499
500 // ListUploadedPartsResult defines result object of ListUploadedParts
501 type ListUploadedPartsResult struct {
502         XMLName              xml.Name       `xml:"ListPartsResult"`
503         Bucket               string         `xml:"Bucket"`               // Bucket name
504         Key                  string         `xml:"Key"`                  // Object name
505         UploadID             string         `xml:"UploadId"`             // Upload ID
506         NextPartNumberMarker string         `xml:"NextPartNumberMarker"` // Next part number
507         MaxParts             int            `xml:"MaxParts"`             // Max parts count
508         IsTruncated          bool           `xml:"IsTruncated"`          // Flag indicates all entries returned.false: all entries returned.
509         UploadedParts        []UploadedPart `xml:"Part"`                 // Uploaded parts
510 }
511
512 // UploadedPart defines uploaded part
513 type UploadedPart struct {
514         XMLName      xml.Name  `xml:"Part"`
515         PartNumber   int       `xml:"PartNumber"`   // Part number
516         LastModified time.Time `xml:"LastModified"` // Last modified time
517         ETag         string    `xml:"ETag"`         // ETag cache
518         Size         int       `xml:"Size"`         // Part size
519 }
520
521 // ListMultipartUploadResult defines result object of ListMultipartUpload
522 type ListMultipartUploadResult struct {
523         XMLName            xml.Name            `xml:"ListMultipartUploadsResult"`
524         Bucket             string              `xml:"Bucket"`                // Bucket name
525         Delimiter          string              `xml:"Delimiter"`             // Delimiter for grouping object.
526         Prefix             string              `xml:"Prefix"`                // Object prefix
527         KeyMarker          string              `xml:"KeyMarker"`             // Object key marker
528         UploadIDMarker     string              `xml:"UploadIdMarker"`        // UploadId marker
529         NextKeyMarker      string              `xml:"NextKeyMarker"`         // Next key marker, if not all entries returned.
530         NextUploadIDMarker string              `xml:"NextUploadIdMarker"`    // Next uploadId marker, if not all entries returned.
531         MaxUploads         int                 `xml:"MaxUploads"`            // Max uploads to return
532         IsTruncated        bool                `xml:"IsTruncated"`           // Flag indicates all entries are returned.
533         Uploads            []UncompletedUpload `xml:"Upload"`                // Ongoing uploads (not completed, not aborted)
534         CommonPrefixes     []string            `xml:"CommonPrefixes>Prefix"` // Common prefixes list.
535 }
536
537 // UncompletedUpload structure wraps an uncompleted upload task
538 type UncompletedUpload struct {
539         XMLName   xml.Name  `xml:"Upload"`
540         Key       string    `xml:"Key"`       // Object name
541         UploadID  string    `xml:"UploadId"`  // The UploadId
542         Initiated time.Time `xml:"Initiated"` // Initialization time in the format such as 2012-02-23T04:18:23.000Z
543 }
544
545 // ProcessObjectResult defines result object of ProcessObject
546 type ProcessObjectResult struct {
547         Bucket   string `json:"bucket"`
548         FileSize int    `json:"fileSize"`
549         Object   string `json:"object"`
550         Status   string `json:"status"`
551 }
552
553 // decodeDeleteObjectsResult decodes deleting objects result in URL encoding
554 func decodeDeleteObjectsResult(result *DeleteObjectVersionsResult) error {
555         var err error
556         for i := 0; i < len(result.DeletedObjectsDetail); i++ {
557                 result.DeletedObjectsDetail[i].Key, err = url.QueryUnescape(result.DeletedObjectsDetail[i].Key)
558                 if err != nil {
559                         return err
560                 }
561         }
562         return nil
563 }
564
565 // decodeListObjectsResult decodes list objects result in URL encoding
566 func decodeListObjectsResult(result *ListObjectsResult) error {
567         var err error
568         result.Prefix, err = url.QueryUnescape(result.Prefix)
569         if err != nil {
570                 return err
571         }
572         result.Marker, err = url.QueryUnescape(result.Marker)
573         if err != nil {
574                 return err
575         }
576         result.Delimiter, err = url.QueryUnescape(result.Delimiter)
577         if err != nil {
578                 return err
579         }
580         result.NextMarker, err = url.QueryUnescape(result.NextMarker)
581         if err != nil {
582                 return err
583         }
584         for i := 0; i < len(result.Objects); i++ {
585                 result.Objects[i].Key, err = url.QueryUnescape(result.Objects[i].Key)
586                 if err != nil {
587                         return err
588                 }
589         }
590         for i := 0; i < len(result.CommonPrefixes); i++ {
591                 result.CommonPrefixes[i], err = url.QueryUnescape(result.CommonPrefixes[i])
592                 if err != nil {
593                         return err
594                 }
595         }
596         return nil
597 }
598
599 // decodeListObjectsResult decodes list objects result in URL encoding
600 func decodeListObjectsResultV2(result *ListObjectsResultV2) error {
601         var err error
602         result.Prefix, err = url.QueryUnescape(result.Prefix)
603         if err != nil {
604                 return err
605         }
606         result.StartAfter, err = url.QueryUnescape(result.StartAfter)
607         if err != nil {
608                 return err
609         }
610         result.Delimiter, err = url.QueryUnescape(result.Delimiter)
611         if err != nil {
612                 return err
613         }
614         result.NextContinuationToken, err = url.QueryUnescape(result.NextContinuationToken)
615         if err != nil {
616                 return err
617         }
618         for i := 0; i < len(result.Objects); i++ {
619                 result.Objects[i].Key, err = url.QueryUnescape(result.Objects[i].Key)
620                 if err != nil {
621                         return err
622                 }
623         }
624         for i := 0; i < len(result.CommonPrefixes); i++ {
625                 result.CommonPrefixes[i], err = url.QueryUnescape(result.CommonPrefixes[i])
626                 if err != nil {
627                         return err
628                 }
629         }
630         return nil
631 }
632
633 // decodeListObjectVersionsResult decodes list version objects result in URL encoding
634 func decodeListObjectVersionsResult(result *ListObjectVersionsResult) error {
635         var err error
636
637         // decode:Delimiter
638         result.Delimiter, err = url.QueryUnescape(result.Delimiter)
639         if err != nil {
640                 return err
641         }
642
643         // decode Prefix
644         result.Prefix, err = url.QueryUnescape(result.Prefix)
645         if err != nil {
646                 return err
647         }
648
649         // decode KeyMarker
650         result.KeyMarker, err = url.QueryUnescape(result.KeyMarker)
651         if err != nil {
652                 return err
653         }
654
655         // decode VersionIdMarker
656         result.VersionIdMarker, err = url.QueryUnescape(result.VersionIdMarker)
657         if err != nil {
658                 return err
659         }
660
661         // decode NextKeyMarker
662         result.NextKeyMarker, err = url.QueryUnescape(result.NextKeyMarker)
663         if err != nil {
664                 return err
665         }
666
667         // decode NextVersionIdMarker
668         result.NextVersionIdMarker, err = url.QueryUnescape(result.NextVersionIdMarker)
669         if err != nil {
670                 return err
671         }
672
673         // decode CommonPrefixes
674         for i := 0; i < len(result.CommonPrefixes); i++ {
675                 result.CommonPrefixes[i], err = url.QueryUnescape(result.CommonPrefixes[i])
676                 if err != nil {
677                         return err
678                 }
679         }
680
681         // decode deleteMarker
682         for i := 0; i < len(result.ObjectDeleteMarkers); i++ {
683                 result.ObjectDeleteMarkers[i].Key, err = url.QueryUnescape(result.ObjectDeleteMarkers[i].Key)
684                 if err != nil {
685                         return err
686                 }
687         }
688
689         // decode ObjectVersions
690         for i := 0; i < len(result.ObjectVersions); i++ {
691                 result.ObjectVersions[i].Key, err = url.QueryUnescape(result.ObjectVersions[i].Key)
692                 if err != nil {
693                         return err
694                 }
695         }
696
697         return nil
698 }
699
700 // decodeListUploadedPartsResult decodes
701 func decodeListUploadedPartsResult(result *ListUploadedPartsResult) error {
702         var err error
703         result.Key, err = url.QueryUnescape(result.Key)
704         if err != nil {
705                 return err
706         }
707         return nil
708 }
709
710 // decodeListMultipartUploadResult decodes list multipart upload result in URL encoding
711 func decodeListMultipartUploadResult(result *ListMultipartUploadResult) error {
712         var err error
713         result.Prefix, err = url.QueryUnescape(result.Prefix)
714         if err != nil {
715                 return err
716         }
717         result.Delimiter, err = url.QueryUnescape(result.Delimiter)
718         if err != nil {
719                 return err
720         }
721         result.KeyMarker, err = url.QueryUnescape(result.KeyMarker)
722         if err != nil {
723                 return err
724         }
725         result.NextKeyMarker, err = url.QueryUnescape(result.NextKeyMarker)
726         if err != nil {
727                 return err
728         }
729         for i := 0; i < len(result.Uploads); i++ {
730                 result.Uploads[i].Key, err = url.QueryUnescape(result.Uploads[i].Key)
731                 if err != nil {
732                         return err
733                 }
734         }
735         for i := 0; i < len(result.CommonPrefixes); i++ {
736                 result.CommonPrefixes[i], err = url.QueryUnescape(result.CommonPrefixes[i])
737                 if err != nil {
738                         return err
739                 }
740         }
741         return nil
742 }
743
744 // createBucketConfiguration defines the configuration for creating a bucket.
745 type createBucketConfiguration struct {
746         XMLName            xml.Name           `xml:"CreateBucketConfiguration"`
747         StorageClass       StorageClassType   `xml:"StorageClass,omitempty"`
748         DataRedundancyType DataRedundancyType `xml:"DataRedundancyType,omitempty"`
749 }
750
751 // LiveChannelConfiguration defines the configuration for live-channel
752 type LiveChannelConfiguration struct {
753         XMLName     xml.Name          `xml:"LiveChannelConfiguration"`
754         Description string            `xml:"Description,omitempty"` //Description of live-channel, up to 128 bytes
755         Status      string            `xml:"Status,omitempty"`      //\bSpecify the status of livechannel
756         Target      LiveChannelTarget `xml:"Target"`                //target configuration of live-channel
757         // use point instead of struct to avoid omit empty snapshot
758         Snapshot *LiveChannelSnapshot `xml:"Snapshot,omitempty"` //snapshot configuration of live-channel
759 }
760
761 // LiveChannelTarget target configuration of live-channel
762 type LiveChannelTarget struct {
763         XMLName      xml.Name `xml:"Target"`
764         Type         string   `xml:"Type"`                   //the type of object, only supports HLS
765         FragDuration int      `xml:"FragDuration,omitempty"` //the length of each ts object (in seconds), in the range [1,100]
766         FragCount    int      `xml:"FragCount,omitempty"`    //the number of ts objects in the m3u8 object, in the range of [1,100]
767         PlaylistName string   `xml:"PlaylistName,omitempty"` //the name of m3u8 object, which must end with ".m3u8" and the length range is [6,128]
768 }
769
770 // LiveChannelSnapshot snapshot configuration of live-channel
771 type LiveChannelSnapshot struct {
772         XMLName     xml.Name `xml:"Snapshot"`
773         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.
774         DestBucket  string   `xml:"DestBucket,omitempty"`  //Bucket the snapshots will be written to. should be the same owner as the source bucket.
775         NotifyTopic string   `xml:"NotifyTopic,omitempty"` //Topics of MNS for notifying users of high frequency screenshot operation results
776         Interval    int      `xml:"Interval,omitempty"`    //interval of snapshots, threre is no snapshot if no I-frame during the interval time
777 }
778
779 // CreateLiveChannelResult the result of crete live-channel
780 type CreateLiveChannelResult struct {
781         XMLName     xml.Name `xml:"CreateLiveChannelResult"`
782         PublishUrls []string `xml:"PublishUrls>Url"` //push urls list
783         PlayUrls    []string `xml:"PlayUrls>Url"`    //play urls list
784 }
785
786 // LiveChannelStat the result of get live-channel state
787 type LiveChannelStat struct {
788         XMLName       xml.Name         `xml:"LiveChannelStat"`
789         Status        string           `xml:"Status"`        //Current push status of live-channel: Disabled,Live,Idle
790         ConnectedTime time.Time        `xml:"ConnectedTime"` //The time when the client starts pushing, format: ISO8601
791         RemoteAddr    string           `xml:"RemoteAddr"`    //The ip address of the client
792         Video         LiveChannelVideo `xml:"Video"`         //Video stream information
793         Audio         LiveChannelAudio `xml:"Audio"`         //Audio stream information
794 }
795
796 // LiveChannelVideo video stream information
797 type LiveChannelVideo struct {
798         XMLName   xml.Name `xml:"Video"`
799         Width     int      `xml:"Width"`     //Width (unit: pixels)
800         Height    int      `xml:"Height"`    //Height (unit: pixels)
801         FrameRate int      `xml:"FrameRate"` //FramRate
802         Bandwidth int      `xml:"Bandwidth"` //Bandwidth (unit: B/s)
803 }
804
805 // LiveChannelAudio audio stream information
806 type LiveChannelAudio struct {
807         XMLName    xml.Name `xml:"Audio"`
808         SampleRate int      `xml:"SampleRate"` //SampleRate
809         Bandwidth  int      `xml:"Bandwidth"`  //Bandwidth (unit: B/s)
810         Codec      string   `xml:"Codec"`      //Encoding forma
811 }
812
813 // LiveChannelHistory the result of GetLiveChannelHistory, at most return up to lastest 10 push records
814 type LiveChannelHistory struct {
815         XMLName xml.Name     `xml:"LiveChannelHistory"`
816         Record  []LiveRecord `xml:"LiveRecord"` //push records list
817 }
818
819 // LiveRecord push recode
820 type LiveRecord struct {
821         XMLName    xml.Name  `xml:"LiveRecord"`
822         StartTime  time.Time `xml:"StartTime"`  //StartTime, format: ISO8601
823         EndTime    time.Time `xml:"EndTime"`    //EndTime, format: ISO8601
824         RemoteAddr string    `xml:"RemoteAddr"` //The ip address of remote client
825 }
826
827 // ListLiveChannelResult the result of ListLiveChannel
828 type ListLiveChannelResult struct {
829         XMLName     xml.Name          `xml:"ListLiveChannelResult"`
830         Prefix      string            `xml:"Prefix"`      //Filter by the name start with the value of "Prefix"
831         Marker      string            `xml:"Marker"`      //cursor from which starting list
832         MaxKeys     int               `xml:"MaxKeys"`     //The maximum count returned. the default value is 100. it cannot be greater than 1000.
833         IsTruncated bool              `xml:"IsTruncated"` //Indicates whether all results have been returned, "true" indicates partial results returned while "false" indicates all results have been returned
834         NextMarker  string            `xml:"NextMarker"`  //NextMarker indicate the Marker value of the next request
835         LiveChannel []LiveChannelInfo `xml:"LiveChannel"` //The infomation of live-channel
836 }
837
838 // LiveChannelInfo the infomation of live-channel
839 type LiveChannelInfo struct {
840         XMLName      xml.Name  `xml:"LiveChannel"`
841         Name         string    `xml:"Name"`            //The name of live-channel
842         Description  string    `xml:"Description"`     //Description of live-channel
843         Status       string    `xml:"Status"`          //Status: disabled or enabled
844         LastModified time.Time `xml:"LastModified"`    //Last modification time, format: ISO8601
845         PublishUrls  []string  `xml:"PublishUrls>Url"` //push urls list
846         PlayUrls     []string  `xml:"PlayUrls>Url"`    //play urls list
847 }
848
849 // Tag a tag for the object
850 type Tag struct {
851         XMLName xml.Name `xml:"Tag"`
852         Key     string   `xml:"Key"`
853         Value   string   `xml:"Value"`
854 }
855
856 // Tagging tagset for the object
857 type Tagging struct {
858         XMLName xml.Name `xml:"Tagging"`
859         Tags    []Tag    `xml:"TagSet>Tag,omitempty"`
860 }
861
862 // for GetObjectTagging return value
863 type GetObjectTaggingResult Tagging
864
865 // VersioningConfig for the bucket
866 type VersioningConfig struct {
867         XMLName xml.Name `xml:"VersioningConfiguration"`
868         Status  string   `xml:"Status"`
869 }
870
871 type GetBucketVersioningResult VersioningConfig
872
873 // Server Encryption rule for the bucket
874 type ServerEncryptionRule struct {
875         XMLName    xml.Name       `xml:"ServerSideEncryptionRule"`
876         SSEDefault SSEDefaultRule `xml:"ApplyServerSideEncryptionByDefault"`
877 }
878
879 // Server Encryption deafult rule for the bucket
880 type SSEDefaultRule struct {
881         XMLName           xml.Name `xml:"ApplyServerSideEncryptionByDefault"`
882         SSEAlgorithm      string   `xml:"SSEAlgorithm,omitempty"`
883         KMSMasterKeyID    string   `xml:"KMSMasterKeyID,omitempty"`
884         KMSDataEncryption string   `xml:"KMSDataEncryption,,omitempty"`
885 }
886
887 type GetBucketEncryptionResult ServerEncryptionRule
888 type GetBucketTaggingResult Tagging
889
890 type BucketStat struct {
891         XMLName              xml.Name `xml:"BucketStat"`
892         Storage              int64    `xml:"Storage"`
893         ObjectCount          int64    `xml:"ObjectCount"`
894         MultipartUploadCount int64    `xml:"MultipartUploadCount"`
895 }
896 type GetBucketStatResult BucketStat
897
898 // RequestPaymentConfiguration define the request payment configuration
899 type RequestPaymentConfiguration struct {
900         XMLName xml.Name `xml:"RequestPaymentConfiguration"`
901         Payer   string   `xml:"Payer,omitempty"`
902 }
903
904 // BucketQoSConfiguration define QoS configuration
905 type BucketQoSConfiguration struct {
906         XMLName                   xml.Name `xml:"QoSConfiguration"`
907         TotalUploadBandwidth      *int     `xml:"TotalUploadBandwidth"`      // Total upload bandwidth
908         IntranetUploadBandwidth   *int     `xml:"IntranetUploadBandwidth"`   // Intranet upload bandwidth
909         ExtranetUploadBandwidth   *int     `xml:"ExtranetUploadBandwidth"`   // Extranet upload bandwidth
910         TotalDownloadBandwidth    *int     `xml:"TotalDownloadBandwidth"`    // Total download bandwidth
911         IntranetDownloadBandwidth *int     `xml:"IntranetDownloadBandwidth"` // Intranet download bandwidth
912         ExtranetDownloadBandwidth *int     `xml:"ExtranetDownloadBandwidth"` // Extranet download bandwidth
913         TotalQPS                  *int     `xml:"TotalQps"`                  // Total Qps
914         IntranetQPS               *int     `xml:"IntranetQps"`               // Intranet Qps
915         ExtranetQPS               *int     `xml:"ExtranetQps"`               // Extranet Qps
916 }
917
918 // UserQoSConfiguration define QoS and Range configuration
919 type UserQoSConfiguration struct {
920         XMLName xml.Name `xml:"QoSConfiguration"`
921         Region  string   `xml:"Region,omitempty"` // Effective area of Qos configuration
922         BucketQoSConfiguration
923 }
924
925 //////////////////////////////////////////////////////////////
926 /////////////////// Select OBject ////////////////////////////
927 //////////////////////////////////////////////////////////////
928
929 type CsvMetaRequest struct {
930         XMLName            xml.Name           `xml:"CsvMetaRequest"`
931         InputSerialization InputSerialization `xml:"InputSerialization"`
932         OverwriteIfExists  *bool              `xml:"OverwriteIfExists,omitempty"`
933 }
934
935 // encodeBase64 encode base64 of the CreateSelectObjectMeta api request params
936 func (meta *CsvMetaRequest) encodeBase64() {
937         meta.InputSerialization.CSV.RecordDelimiter =
938                 base64.StdEncoding.EncodeToString([]byte(meta.InputSerialization.CSV.RecordDelimiter))
939         meta.InputSerialization.CSV.FieldDelimiter =
940                 base64.StdEncoding.EncodeToString([]byte(meta.InputSerialization.CSV.FieldDelimiter))
941         meta.InputSerialization.CSV.QuoteCharacter =
942                 base64.StdEncoding.EncodeToString([]byte(meta.InputSerialization.CSV.QuoteCharacter))
943 }
944
945 type JsonMetaRequest struct {
946         XMLName            xml.Name           `xml:"JsonMetaRequest"`
947         InputSerialization InputSerialization `xml:"InputSerialization"`
948         OverwriteIfExists  *bool              `xml:"OverwriteIfExists,omitempty"`
949 }
950
951 type InputSerialization struct {
952         XMLName         xml.Name `xml:"InputSerialization"`
953         CSV             CSV      `xml:CSV,omitempty`
954         JSON            JSON     `xml:JSON,omitempty`
955         CompressionType string   `xml:"CompressionType,omitempty"`
956 }
957 type CSV struct {
958         XMLName         xml.Name `xml:"CSV"`
959         RecordDelimiter string   `xml:"RecordDelimiter,omitempty"`
960         FieldDelimiter  string   `xml:"FieldDelimiter,omitempty"`
961         QuoteCharacter  string   `xml:"QuoteCharacter,omitempty"`
962 }
963
964 type JSON struct {
965         XMLName  xml.Name `xml:"JSON"`
966         JSONType string   `xml:"Type,omitempty"`
967 }
968
969 // SelectRequest is for the SelectObject request params of json file
970 type SelectRequest struct {
971         XMLName                   xml.Name                  `xml:"SelectRequest"`
972         Expression                string                    `xml:"Expression"`
973         InputSerializationSelect  InputSerializationSelect  `xml:"InputSerialization"`
974         OutputSerializationSelect OutputSerializationSelect `xml:"OutputSerialization"`
975         SelectOptions             SelectOptions             `xml:"Options,omitempty"`
976 }
977 type InputSerializationSelect struct {
978         XMLName         xml.Name        `xml:"InputSerialization"`
979         CsvBodyInput    CSVSelectInput  `xml:CSV,omitempty`
980         JsonBodyInput   JSONSelectInput `xml:JSON,omitempty`
981         CompressionType string          `xml:"CompressionType,omitempty"`
982 }
983 type CSVSelectInput struct {
984         XMLName          xml.Name `xml:"CSV"`
985         FileHeaderInfo   string   `xml:"FileHeaderInfo,omitempty"`
986         RecordDelimiter  string   `xml:"RecordDelimiter,omitempty"`
987         FieldDelimiter   string   `xml:"FieldDelimiter,omitempty"`
988         QuoteCharacter   string   `xml:"QuoteCharacter,omitempty"`
989         CommentCharacter string   `xml:"CommentCharacter,omitempty"`
990         Range            string   `xml:"Range,omitempty"`
991         SplitRange       string
992 }
993 type JSONSelectInput struct {
994         XMLName                 xml.Name `xml:"JSON"`
995         JSONType                string   `xml:"Type,omitempty"`
996         Range                   string   `xml:"Range,omitempty"`
997         ParseJSONNumberAsString *bool    `xml:"ParseJsonNumberAsString"`
998         SplitRange              string
999 }
1000
1001 func (jsonInput *JSONSelectInput) JsonIsEmpty() bool {
1002         if jsonInput.JSONType != "" {
1003                 return false
1004         }
1005         return true
1006 }
1007
1008 type OutputSerializationSelect struct {
1009         XMLName          xml.Name         `xml:"OutputSerialization"`
1010         CsvBodyOutput    CSVSelectOutput  `xml:CSV,omitempty`
1011         JsonBodyOutput   JSONSelectOutput `xml:JSON,omitempty`
1012         OutputRawData    *bool            `xml:"OutputRawData,omitempty"`
1013         KeepAllColumns   *bool            `xml:"KeepAllColumns,omitempty"`
1014         EnablePayloadCrc *bool            `xml:"EnablePayloadCrc,omitempty"`
1015         OutputHeader     *bool            `xml:"OutputHeader,omitempty"`
1016 }
1017 type CSVSelectOutput struct {
1018         XMLName         xml.Name `xml:"CSV"`
1019         RecordDelimiter string   `xml:"RecordDelimiter,omitempty"`
1020         FieldDelimiter  string   `xml:"FieldDelimiter,omitempty"`
1021 }
1022 type JSONSelectOutput struct {
1023         XMLName         xml.Name `xml:"JSON"`
1024         RecordDelimiter string   `xml:"RecordDelimiter,omitempty"`
1025 }
1026
1027 func (selectReq *SelectRequest) encodeBase64() {
1028         if selectReq.InputSerializationSelect.JsonBodyInput.JsonIsEmpty() {
1029                 selectReq.csvEncodeBase64()
1030         } else {
1031                 selectReq.jsonEncodeBase64()
1032         }
1033 }
1034
1035 // csvEncodeBase64 encode base64 of the SelectObject api request params
1036 func (selectReq *SelectRequest) csvEncodeBase64() {
1037         selectReq.Expression = base64.StdEncoding.EncodeToString([]byte(selectReq.Expression))
1038         selectReq.InputSerializationSelect.CsvBodyInput.RecordDelimiter =
1039                 base64.StdEncoding.EncodeToString([]byte(selectReq.InputSerializationSelect.CsvBodyInput.RecordDelimiter))
1040         selectReq.InputSerializationSelect.CsvBodyInput.FieldDelimiter =
1041                 base64.StdEncoding.EncodeToString([]byte(selectReq.InputSerializationSelect.CsvBodyInput.FieldDelimiter))
1042         selectReq.InputSerializationSelect.CsvBodyInput.QuoteCharacter =
1043                 base64.StdEncoding.EncodeToString([]byte(selectReq.InputSerializationSelect.CsvBodyInput.QuoteCharacter))
1044         selectReq.InputSerializationSelect.CsvBodyInput.CommentCharacter =
1045                 base64.StdEncoding.EncodeToString([]byte(selectReq.InputSerializationSelect.CsvBodyInput.CommentCharacter))
1046         selectReq.OutputSerializationSelect.CsvBodyOutput.FieldDelimiter =
1047                 base64.StdEncoding.EncodeToString([]byte(selectReq.OutputSerializationSelect.CsvBodyOutput.FieldDelimiter))
1048         selectReq.OutputSerializationSelect.CsvBodyOutput.RecordDelimiter =
1049                 base64.StdEncoding.EncodeToString([]byte(selectReq.OutputSerializationSelect.CsvBodyOutput.RecordDelimiter))
1050
1051         // handle Range
1052         if selectReq.InputSerializationSelect.CsvBodyInput.Range != "" {
1053                 selectReq.InputSerializationSelect.CsvBodyInput.Range = "line-range=" + selectReq.InputSerializationSelect.CsvBodyInput.Range
1054         }
1055
1056         if selectReq.InputSerializationSelect.CsvBodyInput.SplitRange != "" {
1057                 selectReq.InputSerializationSelect.CsvBodyInput.Range = "split-range=" + selectReq.InputSerializationSelect.CsvBodyInput.SplitRange
1058         }
1059 }
1060
1061 // jsonEncodeBase64 encode base64 of the SelectObject api request params
1062 func (selectReq *SelectRequest) jsonEncodeBase64() {
1063         selectReq.Expression = base64.StdEncoding.EncodeToString([]byte(selectReq.Expression))
1064         selectReq.OutputSerializationSelect.JsonBodyOutput.RecordDelimiter =
1065                 base64.StdEncoding.EncodeToString([]byte(selectReq.OutputSerializationSelect.JsonBodyOutput.RecordDelimiter))
1066
1067         // handle Range
1068         if selectReq.InputSerializationSelect.JsonBodyInput.Range != "" {
1069                 selectReq.InputSerializationSelect.JsonBodyInput.Range = "line-range=" + selectReq.InputSerializationSelect.JsonBodyInput.Range
1070         }
1071
1072         if selectReq.InputSerializationSelect.JsonBodyInput.SplitRange != "" {
1073                 selectReq.InputSerializationSelect.JsonBodyInput.Range = "split-range=" + selectReq.InputSerializationSelect.JsonBodyInput.SplitRange
1074         }
1075 }
1076
1077 // CsvOptions is a element in the SelectObject api request's params
1078 type SelectOptions struct {
1079         XMLName                  xml.Name `xml:"Options"`
1080         SkipPartialDataRecord    *bool    `xml:"SkipPartialDataRecord,omitempty"`
1081         MaxSkippedRecordsAllowed string   `xml:"MaxSkippedRecordsAllowed,omitempty"`
1082 }
1083
1084 // SelectObjectResult is the SelectObject api's return
1085 type SelectObjectResult struct {
1086         Version          byte
1087         FrameType        int32
1088         PayloadLength    int32
1089         HeaderCheckSum   uint32
1090         Offset           uint64
1091         Data             string           // DataFrame
1092         EndFrame         EndFrame         // EndFrame
1093         MetaEndFrameCSV  MetaEndFrameCSV  // MetaEndFrameCSV
1094         MetaEndFrameJSON MetaEndFrameJSON // MetaEndFrameJSON
1095         PayloadChecksum  uint32
1096         ReadFlagInfo
1097 }
1098
1099 // ReadFlagInfo if reading the frame data, recode the reading status
1100 type ReadFlagInfo struct {
1101         OpenLine            bool
1102         ConsumedBytesLength int32
1103         EnablePayloadCrc    bool
1104         OutputRawData       bool
1105 }
1106
1107 // EndFrame is EndFrameType of SelectObject api
1108 type EndFrame struct {
1109         TotalScanned   int64
1110         HTTPStatusCode int32
1111         ErrorMsg       string
1112 }
1113
1114 // MetaEndFrameCSV is MetaEndFrameCSVType of CreateSelectObjectMeta
1115 type MetaEndFrameCSV struct {
1116         TotalScanned int64
1117         Status       int32
1118         SplitsCount  int32
1119         RowsCount    int64
1120         ColumnsCount int32
1121         ErrorMsg     string
1122 }
1123
1124 // MetaEndFrameJSON is MetaEndFrameJSON of CreateSelectObjectMeta
1125 type MetaEndFrameJSON struct {
1126         TotalScanned int64
1127         Status       int32
1128         SplitsCount  int32
1129         RowsCount    int64
1130         ErrorMsg     string
1131 }
1132
1133 // InventoryConfiguration is Inventory config
1134 type InventoryConfiguration struct {
1135         XMLName                xml.Name             `xml:"InventoryConfiguration"`
1136         Id                     string               `xml:"Id,omitempty"`
1137         IsEnabled              *bool                `xml:"IsEnabled,omitempty"`
1138         Prefix                 string               `xml:"Filter>Prefix,omitempty"`
1139         OSSBucketDestination   OSSBucketDestination `xml:"Destination>OSSBucketDestination,omitempty"`
1140         Frequency              string               `xml:"Schedule>Frequency,omitempty"`
1141         IncludedObjectVersions string               `xml:"IncludedObjectVersions,omitempty"`
1142         OptionalFields         OptionalFields       `xml:OptionalFields,omitempty`
1143 }
1144
1145 type OptionalFields struct {
1146         XMLName xml.Name `xml:"OptionalFields,omitempty`
1147         Field   []string `xml:"Field,omitempty`
1148 }
1149
1150 type OSSBucketDestination struct {
1151         XMLName    xml.Name       `xml:"OSSBucketDestination"`
1152         Format     string         `xml:"Format,omitempty"`
1153         AccountId  string         `xml:"AccountId,omitempty"`
1154         RoleArn    string         `xml:"RoleArn,omitempty"`
1155         Bucket     string         `xml:"Bucket,omitempty"`
1156         Prefix     string         `xml:"Prefix,omitempty"`
1157         Encryption *InvEncryption `xml:"Encryption,omitempty"`
1158 }
1159
1160 type InvEncryption struct {
1161         XMLName xml.Name   `xml:"Encryption"`
1162         SseOss  *InvSseOss `xml:"SSE-OSS"`
1163         SseKms  *InvSseKms `xml:"SSE-KMS"`
1164 }
1165
1166 type InvSseOss struct {
1167         XMLName xml.Name `xml:"SSE-OSS"`
1168 }
1169
1170 type InvSseKms struct {
1171         XMLName xml.Name `xml:"SSE-KMS"`
1172         KmsId   string   `xml:"KeyId,omitempty"`
1173 }
1174
1175 type ListInventoryConfigurationsResult struct {
1176         XMLName                xml.Name                 `xml:"ListInventoryConfigurationsResult"`
1177         InventoryConfiguration []InventoryConfiguration `xml:"InventoryConfiguration,omitempty`
1178         IsTruncated            *bool                    `xml:"IsTruncated,omitempty"`
1179         NextContinuationToken  string                   `xml:"NextContinuationToken,omitempty"`
1180 }
1181
1182 // RestoreConfiguration for RestoreObject
1183 type RestoreConfiguration struct {
1184         XMLName xml.Name `xml:"RestoreRequest"`
1185         Days    int32    `xml:"Days,omitempty"`
1186         Tier    string   `xml:"JobParameters>Tier,omitempty"`
1187 }
1188
1189 // AsyncFetchTaskConfiguration for SetBucketAsyncFetchTask
1190 type AsyncFetchTaskConfiguration struct {
1191         XMLName       xml.Name `xml:"AsyncFetchTaskConfiguration"`
1192         Url           string   `xml:"Url,omitempty"`
1193         Object        string   `xml:"Object,omitempty"`
1194         Host          string   `xml:"Host,omitempty"`
1195         ContentMD5    string   `xml:"ContentMD5,omitempty"`
1196         Callback      string   `xml:"Callback,omitempty"`
1197         StorageClass  string   `xml:"StorageClass,omitempty"`
1198         IgnoreSameKey bool     `xml:"IgnoreSameKey"`
1199 }
1200
1201 // AsyncFetchTaskResult for SetBucketAsyncFetchTask result
1202 type AsyncFetchTaskResult struct {
1203         XMLName xml.Name `xml:"AsyncFetchTaskResult"`
1204         TaskId  string   `xml:"TaskId,omitempty"`
1205 }
1206
1207 // AsynFetchTaskInfo for GetBucketAsyncFetchTask result
1208 type AsynFetchTaskInfo struct {
1209         XMLName  xml.Name      `xml:"AsyncFetchTaskInfo"`
1210         TaskId   string        `xml:"TaskId,omitempty"`
1211         State    string        `xml:"State,omitempty"`
1212         ErrorMsg string        `xml:"ErrorMsg,omitempty"`
1213         TaskInfo AsyncTaskInfo `xml:"TaskInfo,omitempty"`
1214 }
1215
1216 // AsyncTaskInfo for async task information
1217 type AsyncTaskInfo struct {
1218         XMLName       xml.Name `xml:"TaskInfo"`
1219         Url           string   `xml:"Url,omitempty"`
1220         Object        string   `xml:"Object,omitempty"`
1221         Host          string   `xml:"Host,omitempty"`
1222         ContentMD5    string   `xml:"ContentMD5,omitempty"`
1223         Callback      string   `xml:"Callback,omitempty"`
1224         StorageClass  string   `xml:"StorageClass,omitempty"`
1225         IgnoreSameKey bool     `xml:"IgnoreSameKey"`
1226 }
1227
1228 // InitiateWormConfiguration define InitiateBucketWorm configuration
1229 type InitiateWormConfiguration struct {
1230         XMLName               xml.Name `xml:"InitiateWormConfiguration"`
1231         RetentionPeriodInDays int      `xml:"RetentionPeriodInDays"` // specify retention days
1232 }
1233
1234 // ExtendWormConfiguration define ExtendWormConfiguration configuration
1235 type ExtendWormConfiguration struct {
1236         XMLName               xml.Name `xml:"ExtendWormConfiguration"`
1237         RetentionPeriodInDays int      `xml:"RetentionPeriodInDays"` // specify retention days
1238 }
1239
1240 // WormConfiguration define WormConfiguration
1241 type WormConfiguration struct {
1242         XMLName               xml.Name `xml:"WormConfiguration"`
1243         WormId                string   `xml:"WormId,omitempty"`
1244         State                 string   `xml:"State,omitempty"`
1245         RetentionPeriodInDays int      `xml:"RetentionPeriodInDays"` // specify retention days
1246         CreationDate          string   `xml:"CreationDate,omitempty"`
1247 }