first to commit project
This commit is contained in:
36
example/bucket/delete.go
Normal file
36
example/bucket/delete.go
Normal file
@@ -0,0 +1,36 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net/url"
|
||||
"os"
|
||||
|
||||
"net/http"
|
||||
|
||||
"github.com/tencentyun/cos-go-sdk-v5"
|
||||
"github.com/tencentyun/cos-go-sdk-v5/debug"
|
||||
)
|
||||
|
||||
func main() {
|
||||
u, _ := url.Parse("https://testdelete-1253846586.cos.ap-guangzhou.myqcloud.com")
|
||||
b := &cos.BaseURL{
|
||||
BucketURL: u,
|
||||
}
|
||||
c := cos.NewClient(b, &http.Client{
|
||||
Transport: &cos.AuthorizationTransport{
|
||||
SecretID: os.Getenv("COS_SECRETID"),
|
||||
SecretKey: os.Getenv("COS_SECRETKEY"),
|
||||
Transport: &debug.DebugRequestTransport{
|
||||
RequestHeader: true,
|
||||
RequestBody: true,
|
||||
ResponseHeader: true,
|
||||
ResponseBody: true,
|
||||
},
|
||||
},
|
||||
})
|
||||
|
||||
_, err := c.Bucket.Delete(context.Background())
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
36
example/bucket/deleteCORS.go
Normal file
36
example/bucket/deleteCORS.go
Normal file
@@ -0,0 +1,36 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net/url"
|
||||
"os"
|
||||
|
||||
"net/http"
|
||||
|
||||
"github.com/tencentyun/cos-go-sdk-v5"
|
||||
"github.com/tencentyun/cos-go-sdk-v5/debug"
|
||||
)
|
||||
|
||||
func main() {
|
||||
u, _ := url.Parse("https://test-1253846586.cos.ap-guangzhou.myqcloud.com")
|
||||
b := &cos.BaseURL{
|
||||
BucketURL: u,
|
||||
}
|
||||
c := cos.NewClient(b, &http.Client{
|
||||
Transport: &cos.AuthorizationTransport{
|
||||
SecretID: os.Getenv("COS_SECRETID"),
|
||||
SecretKey: os.Getenv("COS_SECRETKEY"),
|
||||
Transport: &debug.DebugRequestTransport{
|
||||
RequestHeader: true,
|
||||
RequestBody: true,
|
||||
ResponseHeader: true,
|
||||
ResponseBody: true,
|
||||
},
|
||||
},
|
||||
})
|
||||
|
||||
_, err := c.Bucket.DeleteCORS(context.Background())
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
35
example/bucket/deleteLifecycle.go
Normal file
35
example/bucket/deleteLifecycle.go
Normal file
@@ -0,0 +1,35 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net/url"
|
||||
"os"
|
||||
|
||||
"net/http"
|
||||
"github.com/tencentyun/cos-go-sdk-v5"
|
||||
"github.com/tencentyun/cos-go-sdk-v5/debug"
|
||||
)
|
||||
|
||||
func main() {
|
||||
u, _ := url.Parse("https://test-1253846586.cos.ap-guangzhou.myqcloud.com")
|
||||
b := &cos.BaseURL{
|
||||
BucketURL: u,
|
||||
}
|
||||
c := cos.NewClient(b, &http.Client{
|
||||
Transport: &cos.AuthorizationTransport{
|
||||
SecretID: os.Getenv("COS_SECRETID"),
|
||||
SecretKey: os.Getenv("COS_SECRETKEY"),
|
||||
Transport: &debug.DebugRequestTransport{
|
||||
RequestHeader: true,
|
||||
RequestBody: true,
|
||||
ResponseHeader: true,
|
||||
ResponseBody: true,
|
||||
},
|
||||
},
|
||||
})
|
||||
|
||||
_, err := c.Bucket.DeleteLifecycle(context.Background())
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
36
example/bucket/deleteTagging.go
Normal file
36
example/bucket/deleteTagging.go
Normal file
@@ -0,0 +1,36 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net/url"
|
||||
"os"
|
||||
|
||||
"net/http"
|
||||
|
||||
"github.com/tencentyun/cos-go-sdk-v5"
|
||||
"github.com/tencentyun/cos-go-sdk-v5/debug"
|
||||
)
|
||||
|
||||
func main() {
|
||||
u, _ := url.Parse("https://test-1253846586.cos.ap-guangzhou.myqcloud.com")
|
||||
b := &cos.BaseURL{
|
||||
BucketURL: u,
|
||||
}
|
||||
c := cos.NewClient(b, &http.Client{
|
||||
Transport: &cos.AuthorizationTransport{
|
||||
SecretID: os.Getenv("COS_SECRETID"),
|
||||
SecretKey: os.Getenv("COS_SECRETKEY"),
|
||||
Transport: &debug.DebugRequestTransport{
|
||||
RequestHeader: true,
|
||||
RequestBody: true,
|
||||
ResponseHeader: true,
|
||||
ResponseBody: true,
|
||||
},
|
||||
},
|
||||
})
|
||||
|
||||
_, err := c.Bucket.DeleteTagging(context.Background())
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
46
example/bucket/get.go
Normal file
46
example/bucket/get.go
Normal file
@@ -0,0 +1,46 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"os"
|
||||
|
||||
"net/url"
|
||||
|
||||
"net/http"
|
||||
|
||||
"github.com/tencentyun/cos-go-sdk-v5"
|
||||
"github.com/tencentyun/cos-go-sdk-v5/debug"
|
||||
)
|
||||
|
||||
func main() {
|
||||
u, _ := url.Parse("https://test-1253846586.cos.ap-guangzhou.myqcloud.com")
|
||||
b := &cos.BaseURL{
|
||||
BucketURL: u,
|
||||
}
|
||||
c := cos.NewClient(b, &http.Client{
|
||||
Transport: &cos.AuthorizationTransport{
|
||||
SecretID: os.Getenv("COS_SECRETID"),
|
||||
SecretKey: os.Getenv("COS_SECRETKEY"),
|
||||
Transport: &debug.DebugRequestTransport{
|
||||
RequestHeader: true,
|
||||
RequestBody: true,
|
||||
ResponseHeader: true,
|
||||
ResponseBody: true,
|
||||
},
|
||||
},
|
||||
})
|
||||
|
||||
opt := &cos.BucketGetOptions{
|
||||
Prefix: "test",
|
||||
MaxKeys: 3,
|
||||
}
|
||||
v, _, err := c.Bucket.Get(context.Background(), opt)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
for _, c := range v.Contents {
|
||||
fmt.Printf("%s, %d\n", c.Key, c.Size)
|
||||
}
|
||||
}
|
||||
40
example/bucket/getACL.go
Normal file
40
example/bucket/getACL.go
Normal file
@@ -0,0 +1,40 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"net/url"
|
||||
"os"
|
||||
|
||||
"net/http"
|
||||
|
||||
"github.com/tencentyun/cos-go-sdk-v5"
|
||||
"github.com/tencentyun/cos-go-sdk-v5/debug"
|
||||
)
|
||||
|
||||
func main() {
|
||||
u, _ := url.Parse("https://test-1253846586.cos.ap-guangzhou.myqcloud.com")
|
||||
b := &cos.BaseURL{
|
||||
BucketURL: u,
|
||||
}
|
||||
c := cos.NewClient(b, &http.Client{
|
||||
Transport: &cos.AuthorizationTransport{
|
||||
SecretID: os.Getenv("COS_SECRETID"),
|
||||
SecretKey: os.Getenv("COS_SECRETKEY"),
|
||||
Transport: &debug.DebugRequestTransport{
|
||||
RequestHeader: true,
|
||||
RequestBody: true,
|
||||
ResponseHeader: true,
|
||||
ResponseBody: true,
|
||||
},
|
||||
},
|
||||
})
|
||||
|
||||
v, _, err := c.Bucket.GetACL(context.Background())
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
for _, a := range v.AccessControlList {
|
||||
fmt.Printf("%s, %s, %s\n", a.Grantee.Type, a.Grantee.ID, a.Permission)
|
||||
}
|
||||
}
|
||||
41
example/bucket/getCORS.go
Normal file
41
example/bucket/getCORS.go
Normal file
@@ -0,0 +1,41 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"net/url"
|
||||
"os"
|
||||
|
||||
"net/http"
|
||||
|
||||
"github.com/tencentyun/cos-go-sdk-v5"
|
||||
"github.com/tencentyun/cos-go-sdk-v5/debug"
|
||||
)
|
||||
|
||||
func main() {
|
||||
u, _ := url.Parse("https://test-1253846586.cos.ap-guangzhou.myqcloud.com")
|
||||
b := &cos.BaseURL{
|
||||
BucketURL: u,
|
||||
}
|
||||
c := cos.NewClient(b, &http.Client{
|
||||
Transport: &cos.AuthorizationTransport{
|
||||
SecretID: os.Getenv("COS_SECRETID"),
|
||||
SecretKey: os.Getenv("COS_SECRETKEY"),
|
||||
Transport: &debug.DebugRequestTransport{
|
||||
RequestHeader: true,
|
||||
RequestBody: true,
|
||||
ResponseHeader: true,
|
||||
ResponseBody: true,
|
||||
},
|
||||
},
|
||||
})
|
||||
|
||||
v, _, err := c.Bucket.GetCORS(context.Background())
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
for _, r := range v.Rules {
|
||||
|
||||
fmt.Printf("%s, %s\n", r.AllowedOrigins, r.AllowedMethods)
|
||||
}
|
||||
}
|
||||
40
example/bucket/getLifecycle.go
Normal file
40
example/bucket/getLifecycle.go
Normal file
@@ -0,0 +1,40 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"net/url"
|
||||
"os"
|
||||
|
||||
"net/http"
|
||||
|
||||
"github.com/tencentyun/cos-go-sdk-v5"
|
||||
"github.com/tencentyun/cos-go-sdk-v5/debug"
|
||||
)
|
||||
|
||||
func main() {
|
||||
u, _ := url.Parse("https://test-1253846586.cos.ap-guangzhou.myqcloud.com")
|
||||
b := &cos.BaseURL{
|
||||
BucketURL: u,
|
||||
}
|
||||
c := cos.NewClient(b, &http.Client{
|
||||
Transport: &cos.AuthorizationTransport{
|
||||
SecretID: os.Getenv("COS_SECRETID"),
|
||||
SecretKey: os.Getenv("COS_SECRETKEY"),
|
||||
Transport: &debug.DebugRequestTransport{
|
||||
RequestHeader: true,
|
||||
RequestBody: true,
|
||||
ResponseHeader: true,
|
||||
ResponseBody: true,
|
||||
},
|
||||
},
|
||||
})
|
||||
|
||||
v, _, err := c.Bucket.GetLifecycle(context.Background())
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
for _, r := range v.Rules {
|
||||
fmt.Printf("%s, %s\n", r.Filter.Prefix, r.Status)
|
||||
}
|
||||
}
|
||||
38
example/bucket/getLocation.go
Normal file
38
example/bucket/getLocation.go
Normal file
@@ -0,0 +1,38 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"net/url"
|
||||
"os"
|
||||
|
||||
"net/http"
|
||||
|
||||
"github.com/tencentyun/cos-go-sdk-v5"
|
||||
"github.com/tencentyun/cos-go-sdk-v5/debug"
|
||||
)
|
||||
|
||||
func main() {
|
||||
u, _ := url.Parse("https://test-1253846586.cos.ap-guangzhou.myqcloud.com")
|
||||
b := &cos.BaseURL{
|
||||
BucketURL: u,
|
||||
}
|
||||
c := cos.NewClient(b, &http.Client{
|
||||
Transport: &cos.AuthorizationTransport{
|
||||
SecretID: os.Getenv("COS_SECRETID"),
|
||||
SecretKey: os.Getenv("COS_SECRETKEY"),
|
||||
Transport: &debug.DebugRequestTransport{
|
||||
RequestHeader: true,
|
||||
RequestBody: true,
|
||||
ResponseHeader: true,
|
||||
ResponseBody: true,
|
||||
},
|
||||
},
|
||||
})
|
||||
|
||||
v, _, err := c.Bucket.GetLocation(context.Background())
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
fmt.Printf("%s\n", v.Location)
|
||||
}
|
||||
40
example/bucket/getTagging.go
Normal file
40
example/bucket/getTagging.go
Normal file
@@ -0,0 +1,40 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"net/url"
|
||||
"os"
|
||||
|
||||
"net/http"
|
||||
|
||||
"github.com/tencentyun/cos-go-sdk-v5"
|
||||
"github.com/tencentyun/cos-go-sdk-v5/debug"
|
||||
)
|
||||
|
||||
func main() {
|
||||
u, _ := url.Parse("https://test-1253846586.cos.ap-guangzhou.myqcloud.com")
|
||||
b := &cos.BaseURL{
|
||||
BucketURL: u,
|
||||
}
|
||||
c := cos.NewClient(b, &http.Client{
|
||||
Transport: &cos.AuthorizationTransport{
|
||||
SecretID: os.Getenv("COS_SECRETID"),
|
||||
SecretKey: os.Getenv("COS_SECRETKEY"),
|
||||
Transport: &debug.DebugRequestTransport{
|
||||
RequestHeader: true,
|
||||
RequestBody: true,
|
||||
ResponseHeader: true,
|
||||
ResponseBody: true,
|
||||
},
|
||||
},
|
||||
})
|
||||
|
||||
v, _, err := c.Bucket.GetTagging(context.Background())
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
for _, t := range v.TagSet {
|
||||
fmt.Printf("%s: %s\n", t.Key, t.Value)
|
||||
}
|
||||
}
|
||||
38
example/bucket/head.go
Normal file
38
example/bucket/head.go
Normal file
@@ -0,0 +1,38 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"net/url"
|
||||
"os"
|
||||
|
||||
"net/http"
|
||||
|
||||
"github.com/tencentyun/cos-go-sdk-v5"
|
||||
"github.com/tencentyun/cos-go-sdk-v5/debug"
|
||||
)
|
||||
|
||||
func main() {
|
||||
u, _ := url.Parse("https://test-1253846586.cos.ap-guangzhou.myqcloud.com")
|
||||
b := &cos.BaseURL{
|
||||
BucketURL: u,
|
||||
}
|
||||
c := cos.NewClient(b, &http.Client{
|
||||
Transport: &cos.AuthorizationTransport{
|
||||
SecretID: os.Getenv("COS_SECRETID"),
|
||||
SecretKey: os.Getenv("COS_SECRETKEY"),
|
||||
Transport: &debug.DebugRequestTransport{
|
||||
RequestHeader: true,
|
||||
RequestBody: true,
|
||||
ResponseHeader: true,
|
||||
ResponseBody: true,
|
||||
},
|
||||
},
|
||||
})
|
||||
|
||||
resp, err := c.Bucket.Head(context.Background())
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
fmt.Println(resp.Status)
|
||||
}
|
||||
43
example/bucket/listMultipartUploads.go
Normal file
43
example/bucket/listMultipartUploads.go
Normal file
@@ -0,0 +1,43 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"net/url"
|
||||
"os"
|
||||
|
||||
"net/http"
|
||||
|
||||
"github.com/tencentyun/cos-go-sdk-v5"
|
||||
"github.com/tencentyun/cos-go-sdk-v5/debug"
|
||||
)
|
||||
|
||||
func main() {
|
||||
u, _ := url.Parse("https://test-1253846586.cos.ap-guangzhou.myqcloud.com")
|
||||
b := &cos.BaseURL{
|
||||
BucketURL: u,
|
||||
}
|
||||
c := cos.NewClient(b, &http.Client{
|
||||
Transport: &cos.AuthorizationTransport{
|
||||
SecretID: os.Getenv("COS_SECRETID"),
|
||||
SecretKey: os.Getenv("COS_SECRETKEY"),
|
||||
Transport: &debug.DebugRequestTransport{
|
||||
RequestHeader: true,
|
||||
RequestBody: true,
|
||||
ResponseHeader: true,
|
||||
ResponseBody: true,
|
||||
},
|
||||
},
|
||||
})
|
||||
|
||||
opt := &cos.ListMultipartUploadsOptions{
|
||||
Prefix: "t",
|
||||
}
|
||||
v, _, err := c.Bucket.ListMultipartUploads(context.Background(), opt)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
for _, p := range v.Uploads {
|
||||
fmt.Printf("%s\n", p.Key)
|
||||
}
|
||||
}
|
||||
39
example/bucket/put.go
Normal file
39
example/bucket/put.go
Normal file
@@ -0,0 +1,39 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net/url"
|
||||
"os"
|
||||
|
||||
"net/http"
|
||||
|
||||
"github.com/tencentyun/cos-go-sdk-v5"
|
||||
"github.com/tencentyun/cos-go-sdk-v5/debug"
|
||||
)
|
||||
|
||||
func main() {
|
||||
u, _ := url.Parse("https://testdelete-1253846586.cos.ap-guangzhou.myqcloud.com")
|
||||
b := &cos.BaseURL{
|
||||
BucketURL: u,
|
||||
}
|
||||
c := cos.NewClient(b, &http.Client{
|
||||
Transport: &cos.AuthorizationTransport{
|
||||
SecretID: os.Getenv("COS_SECRETID"),
|
||||
SecretKey: os.Getenv("COS_SECRETKEY"),
|
||||
Transport: &debug.DebugRequestTransport{
|
||||
RequestHeader: true,
|
||||
RequestBody: true,
|
||||
ResponseHeader: true,
|
||||
ResponseBody: true,
|
||||
},
|
||||
},
|
||||
})
|
||||
|
||||
//opt := &cos.BucketPutOptions{
|
||||
// XCosACL: "public-read",
|
||||
//}
|
||||
_, err := c.Bucket.Put(context.Background(), nil)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
65
example/bucket/putACL.go
Normal file
65
example/bucket/putACL.go
Normal file
@@ -0,0 +1,65 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net/url"
|
||||
"os"
|
||||
|
||||
"net/http"
|
||||
|
||||
"github.com/tencentyun/cos-go-sdk-v5"
|
||||
"github.com/tencentyun/cos-go-sdk-v5/debug"
|
||||
)
|
||||
|
||||
func main() {
|
||||
u, _ := url.Parse("https://test-1253846586.cos.ap-guangzhou.myqcloud.com")
|
||||
b := &cos.BaseURL{
|
||||
BucketURL: u,
|
||||
}
|
||||
c := cos.NewClient(b, &http.Client{
|
||||
Transport: &cos.AuthorizationTransport{
|
||||
SecretID: os.Getenv("COS_SECRETID"),
|
||||
SecretKey: os.Getenv("COS_SECRETKEY"),
|
||||
Transport: &debug.DebugRequestTransport{
|
||||
RequestHeader: true,
|
||||
RequestBody: true,
|
||||
ResponseHeader: true,
|
||||
ResponseBody: true,
|
||||
},
|
||||
},
|
||||
})
|
||||
|
||||
// with header
|
||||
opt := &cos.BucketPutACLOptions{
|
||||
Header: &cos.ACLHeaderOptions{
|
||||
XCosACL: "private",
|
||||
},
|
||||
}
|
||||
_, err := c.Bucket.PutACL(context.Background(), opt)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
// with body
|
||||
opt = &cos.BucketPutACLOptions{
|
||||
Body: &cos.ACLXml{
|
||||
Owner: &cos.Owner{
|
||||
ID: "qcs::cam::uin/100000760461:uin/100000760461",
|
||||
},
|
||||
AccessControlList: []cos.ACLGrant{
|
||||
{
|
||||
Grantee: &cos.ACLGrantee{
|
||||
Type: "RootAccount",
|
||||
ID: "qcs::cam::uin/100000760461:uin/100000760461",
|
||||
},
|
||||
|
||||
Permission: "FULL_CONTROL",
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
_, err = c.Bucket.PutACL(context.Background(), opt)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
53
example/bucket/putCORS.go
Normal file
53
example/bucket/putCORS.go
Normal file
@@ -0,0 +1,53 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net/url"
|
||||
"os"
|
||||
|
||||
"net/http"
|
||||
|
||||
"github.com/tencentyun/cos-go-sdk-v5"
|
||||
"github.com/tencentyun/cos-go-sdk-v5/debug"
|
||||
)
|
||||
|
||||
func main() {
|
||||
u, _ := url.Parse("https://test-1253846586.cos.ap-guangzhou.myqcloud.com")
|
||||
b := &cos.BaseURL{
|
||||
BucketURL: u,
|
||||
}
|
||||
c := cos.NewClient(b, &http.Client{
|
||||
Transport: &cos.AuthorizationTransport{
|
||||
SecretID: os.Getenv("COS_SECRETID"),
|
||||
SecretKey: os.Getenv("COS_SECRETKEY"),
|
||||
Transport: &debug.DebugRequestTransport{
|
||||
RequestHeader: true,
|
||||
RequestBody: true,
|
||||
ResponseHeader: true,
|
||||
ResponseBody: true,
|
||||
},
|
||||
},
|
||||
})
|
||||
|
||||
opt := &cos.BucketPutCORSOptions{
|
||||
Rules: []cos.BucketCORSRule{
|
||||
{
|
||||
AllowedOrigins: []string{"http://www.qq.com"},
|
||||
AllowedMethods: []string{"PUT", "GET"},
|
||||
AllowedHeaders: []string{"x-cos-meta-test", "x-cos-xx"},
|
||||
MaxAgeSeconds: 500,
|
||||
ExposeHeaders: []string{"x-cos-meta-test1"},
|
||||
},
|
||||
{
|
||||
ID: "1234",
|
||||
AllowedOrigins: []string{"http://www.baidu.com", "twitter.com"},
|
||||
AllowedMethods: []string{"PUT", "GET"},
|
||||
MaxAgeSeconds: 500,
|
||||
},
|
||||
},
|
||||
}
|
||||
_, err := c.Bucket.PutCORS(context.Background(), opt)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
58
example/bucket/putLifecycle.go
Normal file
58
example/bucket/putLifecycle.go
Normal file
@@ -0,0 +1,58 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net/url"
|
||||
"os"
|
||||
|
||||
"net/http"
|
||||
|
||||
"github.com/tencentyun/cos-go-sdk-v5"
|
||||
"github.com/tencentyun/cos-go-sdk-v5/debug"
|
||||
)
|
||||
|
||||
func main() {
|
||||
u, _ := url.Parse("https://testhuanan-1253846586.cos.ap-guangzhou.myqcloud.com")
|
||||
b := &cos.BaseURL{
|
||||
BucketURL: u,
|
||||
}
|
||||
c := cos.NewClient(b, &http.Client{
|
||||
Transport: &cos.AuthorizationTransport{
|
||||
SecretID: os.Getenv("COS_SECRETID"),
|
||||
SecretKey: os.Getenv("COS_SECRETKEY"),
|
||||
Transport: &debug.DebugRequestTransport{
|
||||
RequestHeader: true,
|
||||
RequestBody: true,
|
||||
ResponseHeader: true,
|
||||
ResponseBody: true,
|
||||
},
|
||||
},
|
||||
})
|
||||
|
||||
lc := &cos.BucketPutLifecycleOptions{
|
||||
Rules: []cos.BucketLifecycleRule{
|
||||
{
|
||||
ID: "1234",
|
||||
Filter: &cos.BucketLifecycleFilter{Prefix: "test"},
|
||||
Status: "Enabled",
|
||||
Transition: &cos.BucketLifecycleTransition{
|
||||
Days: 10,
|
||||
StorageClass: "Standard",
|
||||
},
|
||||
},
|
||||
{
|
||||
ID: "123422",
|
||||
// If used for all objecs set Prefix:""
|
||||
Filter: &cos.BucketLifecycleFilter{Prefix: "gg"},
|
||||
Status: "Disabled",
|
||||
Expiration: &cos.BucketLifecycleExpiration{
|
||||
Days: 10,
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
_, err := c.Bucket.PutLifecycle(context.Background(), lc)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
54
example/bucket/putTagging.go
Normal file
54
example/bucket/putTagging.go
Normal file
@@ -0,0 +1,54 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net/url"
|
||||
"os"
|
||||
"time"
|
||||
|
||||
"net/http"
|
||||
|
||||
"github.com/tencentyun/cos-go-sdk-v5"
|
||||
"github.com/tencentyun/cos-go-sdk-v5/debug"
|
||||
)
|
||||
|
||||
func main() {
|
||||
u, _ := url.Parse("https://test-1253846586.cos.ap-guangzhou.myqcloud.com")
|
||||
b := &cos.BaseURL{
|
||||
BucketURL: u,
|
||||
}
|
||||
c := cos.NewClient(b, &http.Client{
|
||||
Transport: &cos.AuthorizationTransport{
|
||||
SecretID: os.Getenv("COS_SECRETID"),
|
||||
SecretKey: os.Getenv("COS_SECRETKEY"),
|
||||
Transport: &debug.DebugRequestTransport{
|
||||
RequestHeader: true,
|
||||
RequestBody: true,
|
||||
ResponseHeader: true,
|
||||
ResponseBody: true,
|
||||
},
|
||||
},
|
||||
})
|
||||
startTime := time.Now()
|
||||
|
||||
tg := &cos.BucketPutTaggingOptions{
|
||||
TagSet: []cos.BucketTaggingTag{
|
||||
{
|
||||
Key: "test_k2",
|
||||
Value: "test_v2",
|
||||
},
|
||||
{
|
||||
Key: "test_k3",
|
||||
Value: "test_v3",
|
||||
},
|
||||
{
|
||||
Key: startTime.Format("02_Jan_06_15_04_MST"),
|
||||
Value: "test_time",
|
||||
},
|
||||
},
|
||||
}
|
||||
_, err := c.Bucket.PutTagging(context.Background(), tg)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user