Browse Source

update bucket lifecycle

master
jojoliang 4 years ago
parent
commit
cee6b930c2
  1. 14
      bucket_lifecycle.go
  2. 44
      bucket_lifecycle_test.go
  3. 8
      costesting/ci_test.go
  4. 1
      example/bucket/accelerate.go
  5. 11
      example/bucket/getLifecycle.go
  6. 38
      example/bucket/putLifecycle.go
  7. 5
      object_select.go

14
bucket_lifecycle.go

@ -20,8 +20,9 @@ type BucketLifecycleFilter struct {
// BucketLifecycleExpiration is the param of BucketLifecycleRule
type BucketLifecycleExpiration struct {
Date string `xml:"Date,omitempty"`
Days int `xml:"Days,omitempty"`
Date string `xml:"Date,omitempty"`
Days int `xml:"Days,omitempty"`
ExpiredObjectDeleteMarker bool `xml:"ExpiredObjectDeleteMarker,omitempty"`
}
// BucketLifecycleTransition is the param of BucketLifecycleRule
@ -31,6 +32,11 @@ type BucketLifecycleTransition struct {
StorageClass string
}
type BucketLifecycleNoncurrentVersion struct {
NoncurrentDays int `xml:"NoncurrentDays,omitempty"`
StorageClass string `xml:"StorageClass,omitempty"`
}
// BucketLifecycleAbortIncompleteMultipartUpload is the param of BucketLifecycleRule
type BucketLifecycleAbortIncompleteMultipartUpload struct {
DaysAfterInitiation int `xml:"DaysAfterInitiation,omitempty"`
@ -41,9 +47,11 @@ type BucketLifecycleRule struct {
ID string `xml:"ID,omitempty"`
Status string
Filter *BucketLifecycleFilter `xml:"Filter,omitempty"`
Transition *BucketLifecycleTransition `xml:"Transition,omitempty"`
Transition []BucketLifecycleTransition `xml:"Transition,omitempty"`
Expiration *BucketLifecycleExpiration `xml:"Expiration,omitempty"`
AbortIncompleteMultipartUpload *BucketLifecycleAbortIncompleteMultipartUpload `xml:"AbortIncompleteMultipartUpload,omitempty"`
NoncurrentVersionTransition []BucketLifecycleNoncurrentVersion `xml:"NoncurrentVersionTransition,omitempty"`
NoncurrentVersionExpiration *BucketLifecycleNoncurrentVersion `xml:"NoncurrentVersionExpiration,omitempty"`
}
// BucketGetLifecycleResult is the result of BucketGetLifecycle

44
bucket_lifecycle_test.go

@ -36,6 +36,20 @@ func TestBucketService_GetLifecycle(t *testing.T) {
<Days>10</Days>
<StorageClass>Standard</StorageClass>
</Transition>
<Expiration>
<Days>10</Days>
</Expiration>
<NoncurrentVersionTransition>
<NoncurrentDays>90</NoncurrentDays>
<StorageClass>ARCHIVE</StorageClass>
</NoncurrentVersionTransition>
<NoncurrentVersionTransition>
<NoncurrentDays>180</NoncurrentDays>
<StorageClass>DEEP_ARCHIVE</StorageClass>
</NoncurrentVersionTransition>
<NoncurrentVersionExpiration>
<NoncurrentDays>360</NoncurrentDays>
</NoncurrentVersionExpiration>
</Rule>
<Rule>
<ID>123422</ID>
@ -68,8 +82,24 @@ func TestBucketService_GetLifecycle(t *testing.T) {
},
},
},
Status: "Enabled",
Transition: &BucketLifecycleTransition{Days: 10, StorageClass: "Standard"},
Status: "Enabled",
Transition: []BucketLifecycleTransition{
{Days: 10, StorageClass: "Standard"},
},
Expiration: &BucketLifecycleExpiration{Days: 10},
NoncurrentVersionExpiration: &BucketLifecycleNoncurrentVersion{
NoncurrentDays: 360,
},
NoncurrentVersionTransition: []BucketLifecycleNoncurrentVersion{
{
NoncurrentDays: 90,
StorageClass: "ARCHIVE",
},
{
NoncurrentDays: 180,
StorageClass: "DEEP_ARCHIVE",
},
},
},
{
ID: "123422",
@ -92,10 +122,12 @@ func TestBucketService_PutLifecycle(t *testing.T) {
opt := &BucketPutLifecycleOptions{
Rules: []BucketLifecycleRule{
{
ID: "1234",
Filter: &BucketLifecycleFilter{Prefix: "test"},
Status: "Enabled",
Transition: &BucketLifecycleTransition{Days: 10, StorageClass: "Standard"},
ID: "1234",
Filter: &BucketLifecycleFilter{Prefix: "test"},
Status: "Enabled",
Transition: []BucketLifecycleTransition{
{Days: 10, StorageClass: "Standard"},
},
},
{
ID: "123422",

8
costesting/ci_test.go

@ -355,9 +355,11 @@ func (s *CosTestSuite) TestPutGetDeleteLifeCycle() {
ID: "1234",
Filter: &cos.BucketLifecycleFilter{Prefix: "test"},
Status: "Enabled",
Transition: &cos.BucketLifecycleTransition{
Days: 10,
StorageClass: "Standard",
Transition: []cos.BucketLifecycleTransition{
{
Days: 10,
StorageClass: "Standard",
},
},
},
},

1
example/bucket/accelerate.go

@ -53,7 +53,6 @@ func main() {
opt := &cos.BucketPutAccelerateOptions{
Status: "Enabled",
Type: "COS",
}
_, err = c.Bucket.PutAccelerate(context.Background(), opt)
log_status(err)

11
example/bucket/getLifecycle.go

@ -13,7 +13,7 @@ import (
)
func main() {
u, _ := url.Parse("https://test-1253846586.cos.ap-guangzhou.myqcloud.com")
u, _ := url.Parse("https://test-1259654469.cos.ap-guangzhou.myqcloud.com")
b := &cos.BaseURL{
BucketURL: u,
}
@ -35,6 +35,13 @@ func main() {
panic(err)
}
for _, r := range v.Rules {
fmt.Printf("%s, %s\n", r.Filter.Prefix, r.Status)
fmt.Printf("%+v\n", r.ID)
fmt.Printf("%+v\n", r.Filter)
fmt.Printf("%+v\n", r.Status)
fmt.Printf("%+v\n", r.Transition)
fmt.Printf("%+v\n", r.Expiration)
fmt.Printf("%+v\n", r.NoncurrentVersionExpiration)
fmt.Printf("%+v\n", r.NoncurrentVersionTransition)
fmt.Printf("%+v\n", r.AbortIncompleteMultipartUpload)
}
}

38
example/bucket/putLifecycle.go

@ -12,7 +12,7 @@ import (
)
func main() {
u, _ := url.Parse("https://testhuanan-1253846586.cos.ap-guangzhou.myqcloud.com")
u, _ := url.Parse("https://test-1259654469.cos.ap-guangzhou.myqcloud.com")
b := &cos.BaseURL{
BucketURL: u,
}
@ -35,18 +35,34 @@ func main() {
ID: "1234",
Filter: &cos.BucketLifecycleFilter{Prefix: "test"},
Status: "Enabled",
Transition: &cos.BucketLifecycleTransition{
Days: 10,
StorageClass: "Standard",
Transition: []cos.BucketLifecycleTransition{
{
Days: 30,
StorageClass: "STANDARD_IA",
},
{
Days: 90,
StorageClass: "ARCHIVE",
},
},
},
{
ID: "123422",
// If used for all objecs set Prefix:""
Filter: &cos.BucketLifecycleFilter{Prefix: "gg"},
Status: "Disabled",
Expiration: &cos.BucketLifecycleExpiration{
Days: 10,
Days: 360,
},
NoncurrentVersionExpiration: &cos.BucketLifecycleNoncurrentVersion{
NoncurrentDays: 360,
},
NoncurrentVersionTransition: []cos.BucketLifecycleNoncurrentVersion{
{
NoncurrentDays: 90,
StorageClass: "ARCHIVE",
},
{
NoncurrentDays: 180,
StorageClass: "DEEP_ARCHIVE",
},
},
AbortIncompleteMultipartUpload: &cos.BucketLifecycleAbortIncompleteMultipartUpload{
DaysAfterInitiation: 90,
},
},
},

5
object_select.go

@ -401,7 +401,6 @@ func (osr *ObjectSelectResponse) fixedLengthRead(p []byte, read_timeout int64) (
timeout := time.Duration(read_timeout)
r := osr.Body
ch := make(chan chanReadIO, 1)
defer close(ch)
go func(p []byte) {
var needLen int
readChan := chanReadIO{}
@ -412,6 +411,7 @@ func (osr *ObjectSelectResponse) fixedLengthRead(p []byte, read_timeout int64) (
if err != nil {
readChan.err = err
ch <- readChan
close(ch)
return
}
@ -420,11 +420,12 @@ func (osr *ObjectSelectResponse) fixedLengthRead(p []byte, read_timeout int64) (
}
}
ch <- readChan
close(ch)
}(p)
select {
case <-time.After(time.Second * timeout):
return 0, fmt.Errorf("requestId: %s, readLen timeout, timeout is %d(second),need read:%d", "sr.Headers.Get(HTTPHeaderOssRequestID)", timeout, len(p))
return 0, fmt.Errorf("requestId: %s, readLen timeout, timeout is %d(second),need read:%d", osr.Headers.Get("x-cos-request-id"), timeout, len(p))
case result := <-ch:
return result.readLen, result.err
}

Loading…
Cancel
Save