first to commit project
This commit is contained in:
8
example/README.md
Normal file
8
example/README.md
Normal file
@@ -0,0 +1,8 @@
|
||||
|
||||
|
||||
```
|
||||
export COS_SECRETID=xx
|
||||
export COS_SECRETKEY=xxx
|
||||
|
||||
go run xxx.go
|
||||
```
|
||||
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)
|
||||
}
|
||||
}
|
||||
43
example/object/MutiUpload.go
Normal file
43
example/object/MutiUpload.go
Normal file
@@ -0,0 +1,43 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net/url"
|
||||
"os"
|
||||
"time"
|
||||
"net/http"
|
||||
|
||||
"fmt"
|
||||
"github.com/tencentyun/cos-go-sdk-v5"
|
||||
"github.com/tencentyun/cos-go-sdk-v5/debug"
|
||||
)
|
||||
|
||||
func main() {
|
||||
u, _ := url.Parse("http://tencentyun02-1252448703.cos.ap-guangzhou.myqcloud.com")
|
||||
b := &cos.BaseURL{BucketURL: u}
|
||||
c := cos.NewClient(b, &http.Client{
|
||||
//设置超时时间
|
||||
Timeout: 100 * time.Second,
|
||||
Transport: &cos.AuthorizationTransport{
|
||||
SecretID: os.Getenv("COS_Key"),
|
||||
SecretKey: os.Getenv("COS_Secret"),
|
||||
Transport: &debug.DebugRequestTransport{
|
||||
RequestHeader: false,
|
||||
RequestBody: false,
|
||||
ResponseHeader: false,
|
||||
ResponseBody: false,
|
||||
},
|
||||
},
|
||||
})
|
||||
f,err:=os.Open("E:/cos-php-sdk.zip")
|
||||
if err!=nil {panic(err)}
|
||||
opt := &cos.MultiUploadOptions{
|
||||
OptIni: nil,
|
||||
PartSize:1,
|
||||
}
|
||||
v, _, err := c.Object.MultiUpload(
|
||||
context.Background(), "test", f, opt,
|
||||
)
|
||||
if err!=nil {panic(err)}
|
||||
fmt.Println(v)
|
||||
}
|
||||
43
example/object/abortMultipartUpload.go
Normal file
43
example/object/abortMultipartUpload.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: false,
|
||||
ResponseHeader: true,
|
||||
ResponseBody: true,
|
||||
},
|
||||
},
|
||||
})
|
||||
|
||||
name := "test_multipart.txt"
|
||||
v, _, err := c.Object.InitiateMultipartUpload(context.Background(), name, nil)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
fmt.Printf("%s\n", v.UploadID)
|
||||
|
||||
resp, err := c.Object.AbortMultipartUpload(context.Background(), name, v.UploadID)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
fmt.Printf("%s\n", resp.Status)
|
||||
}
|
||||
75
example/object/append.go
Normal file
75
example/object/append.go
Normal file
@@ -0,0 +1,75 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"fmt"
|
||||
"math/rand"
|
||||
"net/url"
|
||||
"os"
|
||||
"time"
|
||||
|
||||
"net/http"
|
||||
|
||||
"github.com/tencentyun/cos-go-sdk-v5"
|
||||
"github.com/tencentyun/cos-go-sdk-v5/debug"
|
||||
)
|
||||
|
||||
func genBigData(blockSize int) []byte {
|
||||
b := make([]byte, blockSize)
|
||||
if _, err := rand.Read(b); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return b
|
||||
}
|
||||
|
||||
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: false,
|
||||
ResponseHeader: true,
|
||||
ResponseBody: true,
|
||||
},
|
||||
},
|
||||
})
|
||||
|
||||
startTime := time.Now()
|
||||
|
||||
name := fmt.Sprintf("test/test_object_append_%s", startTime.Format(time.RFC3339))
|
||||
data := genBigData(1024 * 1024 * 1)
|
||||
length := len(data)
|
||||
r := bytes.NewReader(data)
|
||||
|
||||
ctx := context.Background()
|
||||
|
||||
// 第一次就必须 append
|
||||
resp, err := c.Object.Append(ctx, name, 0, r, nil)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
return
|
||||
}
|
||||
fmt.Printf("%s\n", resp.Status)
|
||||
|
||||
// head
|
||||
if _, err = c.Object.Head(ctx, name, nil); err != nil {
|
||||
panic(err)
|
||||
return
|
||||
}
|
||||
|
||||
// 再次 append
|
||||
data = genBigData(1024 * 1024 * 5)
|
||||
r = bytes.NewReader(data)
|
||||
resp, err = c.Object.Append(context.Background(), name, length, r, nil)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
fmt.Printf("%s\n", resp.Status)
|
||||
}
|
||||
95
example/object/completeMultipartUpload.go
Normal file
95
example/object/completeMultipartUpload.go
Normal file
@@ -0,0 +1,95 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"math/rand"
|
||||
"net/url"
|
||||
"os"
|
||||
"strings"
|
||||
|
||||
"net/http"
|
||||
|
||||
"github.com/tencentyun/cos-go-sdk-v5"
|
||||
"github.com/tencentyun/cos-go-sdk-v5/debug"
|
||||
)
|
||||
|
||||
func initUpload(c *cos.Client, name string) *cos.InitiateMultipartUploadResult {
|
||||
v, _, err := c.Object.InitiateMultipartUpload(context.Background(), name, nil)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
fmt.Printf("%#v\n", v)
|
||||
return v
|
||||
}
|
||||
|
||||
func uploadPart(c *cos.Client, name string, uploadID string, blockSize, n int) string {
|
||||
|
||||
b := make([]byte, blockSize)
|
||||
if _, err := rand.Read(b); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
s := fmt.Sprintf("%X", b)
|
||||
f := strings.NewReader(s)
|
||||
|
||||
resp, err := c.Object.UploadPart(
|
||||
context.Background(), name, uploadID, n, f, nil,
|
||||
)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
fmt.Printf("%s\n", resp.Status)
|
||||
return resp.Header.Get("Etag")
|
||||
}
|
||||
|
||||
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: false,
|
||||
ResponseHeader: true,
|
||||
ResponseBody: true,
|
||||
},
|
||||
},
|
||||
})
|
||||
|
||||
name := "test/test_complete_upload.go"
|
||||
up := initUpload(c, name)
|
||||
uploadID := up.UploadID
|
||||
blockSize := 1024 * 1024 * 3
|
||||
|
||||
opt := &cos.CompleteMultipartUploadOptions{}
|
||||
for i := 1; i < 5; i++ {
|
||||
etag := uploadPart(c, name, uploadID, blockSize, i)
|
||||
opt.Parts = append(opt.Parts, cos.Object{
|
||||
PartNumber: i, ETag: etag},
|
||||
)
|
||||
}
|
||||
|
||||
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, resp, err := c.Object.CompleteMultipartUpload(
|
||||
context.Background(), name, uploadID, opt,
|
||||
)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
fmt.Printf("%s\n", resp.Status)
|
||||
fmt.Printf("%#v\n", v)
|
||||
fmt.Printf("%s\n", v.Location)
|
||||
}
|
||||
63
example/object/copy.go
Normal file
63
example/object/copy.go
Normal file
@@ -0,0 +1,63 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net/url"
|
||||
"os"
|
||||
"strings"
|
||||
|
||||
"net/http"
|
||||
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"time"
|
||||
|
||||
"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,
|
||||
},
|
||||
},
|
||||
})
|
||||
|
||||
source := "test/objectMove1.go"
|
||||
expected := "test"
|
||||
f := strings.NewReader(expected)
|
||||
|
||||
_, err := c.Object.Put(context.Background(), source, f, nil)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
soruceURL := fmt.Sprintf("%s/%s", u.Host, source)
|
||||
dest := fmt.Sprintf("test/objectMove_%d.go", time.Now().Nanosecond())
|
||||
//opt := &cos.ObjectCopyOptions{}
|
||||
res, _, err := c.Object.Copy(context.Background(), dest, soruceURL, nil)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
fmt.Printf("%+v\n\n", res)
|
||||
|
||||
resp, err := c.Object.Get(context.Background(), dest, nil)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
bs, _ := ioutil.ReadAll(resp.Body)
|
||||
resp.Body.Close()
|
||||
result := string(bs)
|
||||
if result != expected {
|
||||
panic(fmt.Sprintf("%s != %s", result, expected))
|
||||
}
|
||||
}
|
||||
36
example/object/delete.go
Normal file
36
example/object/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://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,
|
||||
},
|
||||
},
|
||||
})
|
||||
|
||||
name := "test/objectPut.go"
|
||||
|
||||
_, err := c.Object.Delete(context.Background(), name)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
102
example/object/deleteMultiple.go
Normal file
102
example/object/deleteMultiple.go
Normal file
@@ -0,0 +1,102 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"net/url"
|
||||
"os"
|
||||
"time"
|
||||
|
||||
"bytes"
|
||||
"io"
|
||||
|
||||
"math/rand"
|
||||
|
||||
"net/http"
|
||||
|
||||
"github.com/tencentyun/cos-go-sdk-v5"
|
||||
"github.com/tencentyun/cos-go-sdk-v5/debug"
|
||||
)
|
||||
|
||||
func genBigData(blockSize int) []byte {
|
||||
b := make([]byte, blockSize)
|
||||
if _, err := rand.Read(b); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return b
|
||||
}
|
||||
|
||||
func uploadMulti(c *cos.Client) []string {
|
||||
names := []string{}
|
||||
data := genBigData(1024 * 1024 * 1)
|
||||
ctx := context.Background()
|
||||
var r io.Reader
|
||||
var name string
|
||||
n := 3
|
||||
|
||||
for n > 0 {
|
||||
name = fmt.Sprintf("test/test_multi_delete_%s", time.Now().Format(time.RFC3339))
|
||||
r = bytes.NewReader(data)
|
||||
|
||||
c.Object.Put(ctx, name, r, nil)
|
||||
names = append(names, name)
|
||||
n--
|
||||
}
|
||||
return names
|
||||
}
|
||||
|
||||
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: false,
|
||||
ResponseHeader: true,
|
||||
ResponseBody: true,
|
||||
},
|
||||
},
|
||||
})
|
||||
ctx := context.Background()
|
||||
|
||||
names := uploadMulti(c)
|
||||
names = append(names, []string{"a", "b", "c", "a+bc/xx&?+# "}...)
|
||||
obs := []cos.Object{}
|
||||
for _, v := range names {
|
||||
obs = append(obs, cos.Object{Key: v})
|
||||
}
|
||||
//sha1 := ""
|
||||
opt := &cos.ObjectDeleteMultiOptions{
|
||||
Objects: obs,
|
||||
//XCosSha1: sha1,
|
||||
//Quiet: true,
|
||||
}
|
||||
|
||||
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.Object.DeleteMulti(ctx, opt)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
for _, x := range v.DeletedObjects {
|
||||
fmt.Printf("deleted %s\n", x.Key)
|
||||
}
|
||||
for _, x := range v.Errors {
|
||||
fmt.Printf("error %s, %s, %s\n", x.Key, x.Code, x.Message)
|
||||
}
|
||||
}
|
||||
54
example/object/get.go
Normal file
54
example/object/get.go
Normal file
@@ -0,0 +1,54 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"net/url"
|
||||
"os"
|
||||
|
||||
"io/ioutil"
|
||||
|
||||
"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,
|
||||
},
|
||||
},
|
||||
})
|
||||
|
||||
name := "test/hello.txt"
|
||||
resp, err := c.Object.Get(context.Background(), name, nil)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
bs, _ := ioutil.ReadAll(resp.Body)
|
||||
resp.Body.Close()
|
||||
fmt.Printf("%s\n", string(bs))
|
||||
|
||||
// range
|
||||
opt := &cos.ObjectGetOptions{
|
||||
ResponseContentType: "text/html",
|
||||
Range: "bytes=0-3",
|
||||
}
|
||||
resp, err = c.Object.Get(context.Background(), name, opt)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
bs, _ = ioutil.ReadAll(resp.Body)
|
||||
resp.Body.Close()
|
||||
fmt.Printf("%s\n", string(bs))
|
||||
}
|
||||
40
example/object/getACL.go
Normal file
40
example/object/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,
|
||||
},
|
||||
},
|
||||
})
|
||||
|
||||
name := "test/hello.txt"
|
||||
v, _, err := c.Object.GetACL(context.Background(), name)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
for _, a := range v.AccessControlList {
|
||||
fmt.Printf("%s, %s, %s\n", a.Grantee.Type, a.Grantee.ID, a.Permission)
|
||||
}
|
||||
|
||||
}
|
||||
45
example/object/getAnonymous.go
Normal file
45
example/object/getAnonymous.go
Normal file
@@ -0,0 +1,45 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"net/url"
|
||||
"strings"
|
||||
|
||||
"io/ioutil"
|
||||
|
||||
"github.com/tencentyun/cos-go-sdk-v5"
|
||||
)
|
||||
|
||||
func upload(c *cos.Client, name string) {
|
||||
f := strings.NewReader("test")
|
||||
f = strings.NewReader("test xxx")
|
||||
opt := &cos.ObjectPutOptions{
|
||||
ObjectPutHeaderOptions: &cos.ObjectPutHeaderOptions{
|
||||
ContentType: "text/html",
|
||||
},
|
||||
ACLHeaderOptions: &cos.ACLHeaderOptions{
|
||||
XCosACL: "public-read",
|
||||
},
|
||||
}
|
||||
c.Object.Put(context.Background(), name, f, opt)
|
||||
return
|
||||
}
|
||||
|
||||
func main() {
|
||||
u, _ := url.Parse("https://test-1253846586.cos.ap-guangzhou.myqcloud.com")
|
||||
b := &cos.BaseURL{BucketURL: u}
|
||||
c := cos.NewClient(b, nil)
|
||||
|
||||
name := "test/anonymous_get.go"
|
||||
upload(c, name)
|
||||
|
||||
resp, err := c.Object.Get(context.Background(), name, nil)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
return
|
||||
}
|
||||
bs, _ := ioutil.ReadAll(resp.Body)
|
||||
defer resp.Body.Close()
|
||||
fmt.Printf("%s\n", string(bs))
|
||||
}
|
||||
35
example/object/head.go
Normal file
35
example/object/head.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,
|
||||
},
|
||||
},
|
||||
})
|
||||
|
||||
name := "test/hello.txt"
|
||||
_, err := c.Object.Head(context.Background(), name, nil)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
38
example/object/initiateMultipartUpload.go
Normal file
38
example/object/initiateMultipartUpload.go
Normal file
@@ -0,0 +1,38 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"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,
|
||||
},
|
||||
},
|
||||
})
|
||||
|
||||
name := "test_multipart" + time.Now().Format(time.RFC3339)
|
||||
v, _, err := c.Object.InitiateMultipartUpload(context.Background(), name, nil)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
fmt.Printf("%s\n", v.UploadID)
|
||||
}
|
||||
81
example/object/listParts.go
Normal file
81
example/object/listParts.go
Normal file
@@ -0,0 +1,81 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"math/rand"
|
||||
"net/url"
|
||||
"os"
|
||||
"strings"
|
||||
|
||||
"net/http"
|
||||
|
||||
"github.com/tencentyun/cos-go-sdk-v5"
|
||||
"github.com/tencentyun/cos-go-sdk-v5/debug"
|
||||
)
|
||||
|
||||
func initUpload(c *cos.Client, name string) *cos.InitiateMultipartUploadResult {
|
||||
v, _, err := c.Object.InitiateMultipartUpload(context.Background(), name, nil)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
fmt.Printf("%#v\n", v)
|
||||
return v
|
||||
}
|
||||
|
||||
func uploadPart(c *cos.Client, name string, uploadID string, blockSize, n int) string {
|
||||
|
||||
b := make([]byte, blockSize)
|
||||
if _, err := rand.Read(b); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
s := fmt.Sprintf("%X", b)
|
||||
f := strings.NewReader(s)
|
||||
|
||||
resp, err := c.Object.UploadPart(
|
||||
context.Background(), name, uploadID, n, f, nil,
|
||||
)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
fmt.Printf("%s\n", resp.Status)
|
||||
return resp.Header.Get("Etag")
|
||||
}
|
||||
|
||||
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: false,
|
||||
ResponseHeader: true,
|
||||
ResponseBody: true,
|
||||
},
|
||||
},
|
||||
})
|
||||
|
||||
name := "test/test_list_parts.go"
|
||||
up := initUpload(c, name)
|
||||
uploadID := up.UploadID
|
||||
ctx := context.Background()
|
||||
blockSize := 1024 * 1024 * 3
|
||||
|
||||
for i := 1; i < 5; i++ {
|
||||
uploadPart(c, name, uploadID, blockSize, i)
|
||||
}
|
||||
|
||||
v, _, err := c.Object.ListParts(ctx, name, uploadID)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
return
|
||||
}
|
||||
for _, p := range v.Parts {
|
||||
fmt.Printf("%d, %s, %d\n", p.PartNumber, p.ETag, p.Size)
|
||||
}
|
||||
fmt.Printf("%s\n", v.Initiator.ID)
|
||||
fmt.Printf("%s\n", v.Owner.ID)
|
||||
}
|
||||
39
example/object/options.go
Normal file
39
example/object/options.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://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,
|
||||
},
|
||||
},
|
||||
})
|
||||
|
||||
name := "test/hello.txt"
|
||||
opt := &cos.ObjectOptionsOptions{
|
||||
Origin: "http://www.qq.com",
|
||||
AccessControlRequestMethod: "PUT",
|
||||
}
|
||||
_, err := c.Object.Options(context.Background(), name, opt)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
54
example/object/put.go
Normal file
54
example/object/put.go
Normal file
@@ -0,0 +1,54 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net/url"
|
||||
"os"
|
||||
"strings"
|
||||
|
||||
"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,
|
||||
},
|
||||
},
|
||||
})
|
||||
|
||||
name := "test/objectPut.go"
|
||||
f := strings.NewReader("test")
|
||||
|
||||
_, err := c.Object.Put(context.Background(), name, f, nil)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
name = "test/put_option.go"
|
||||
f = strings.NewReader("test xxx")
|
||||
opt := &cos.ObjectPutOptions{
|
||||
ObjectPutHeaderOptions: &cos.ObjectPutHeaderOptions{
|
||||
ContentType: "text/html",
|
||||
},
|
||||
ACLHeaderOptions: &cos.ACLHeaderOptions{
|
||||
//XCosACL: "public-read",
|
||||
XCosACL: "private",
|
||||
},
|
||||
}
|
||||
_, err = c.Object.Put(context.Background(), name, f, opt)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
64
example/object/putACL.go
Normal file
64
example/object/putACL.go
Normal file
@@ -0,0 +1,64 @@
|
||||
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.ObjectPutACLOptions{
|
||||
Header: &cos.ACLHeaderOptions{
|
||||
XCosACL: "private",
|
||||
},
|
||||
}
|
||||
name := "test/hello.txt"
|
||||
_, err := c.Object.PutACL(context.Background(), name, opt)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
// with body
|
||||
opt = &cos.ObjectPutACLOptions{
|
||||
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.Object.PutACL(context.Background(), name, opt)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
53
example/object/uploadFile.go
Normal file
53
example/object/uploadFile.go
Normal file
@@ -0,0 +1,53 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net/url"
|
||||
"os"
|
||||
|
||||
"net/http"
|
||||
|
||||
"fmt"
|
||||
|
||||
"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_Key"),
|
||||
SecretKey: os.Getenv("COS_Secret"),
|
||||
Transport: &debug.DebugRequestTransport{
|
||||
RequestHeader: true,
|
||||
RequestBody: false,
|
||||
ResponseHeader: true,
|
||||
ResponseBody: true,
|
||||
},
|
||||
},
|
||||
})
|
||||
|
||||
name := "test/uploadFile.go"
|
||||
f, err := os.Open(os.Args[0])
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
s, err := f.Stat()
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
fmt.Println(s.Size())
|
||||
opt := &cos.ObjectPutOptions{
|
||||
ObjectPutHeaderOptions: &cos.ObjectPutHeaderOptions{
|
||||
ContentLength: int(s.Size()),
|
||||
},
|
||||
}
|
||||
//opt.ContentLength = int(s.Size())
|
||||
|
||||
_, err = c.Object.Put(context.Background(), name, f, opt)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
53
example/object/uploadPart.go
Normal file
53
example/object/uploadPart.go
Normal file
@@ -0,0 +1,53 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"os"
|
||||
|
||||
"net/url"
|
||||
"strings"
|
||||
|
||||
"net/http"
|
||||
|
||||
"github.com/tencentyun/cos-go-sdk-v5"
|
||||
"github.com/tencentyun/cos-go-sdk-v5/debug"
|
||||
)
|
||||
|
||||
func initUpload(c *cos.Client, name string) *cos.InitiateMultipartUploadResult {
|
||||
v, _, err := c.Object.InitiateMultipartUpload(context.Background(), name, nil)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
fmt.Printf("%#v\n", v)
|
||||
return v
|
||||
}
|
||||
|
||||
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,
|
||||
},
|
||||
},
|
||||
})
|
||||
|
||||
name := "test/test_multi_upload.go"
|
||||
up := initUpload(c, name)
|
||||
uploadID := up.UploadID
|
||||
|
||||
f := strings.NewReader("test heoo")
|
||||
_, err := c.Object.UploadPart(
|
||||
context.Background(), name, uploadID, 1, f, nil,
|
||||
)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
36
example/service/get.go
Normal file
36
example/service/get.go
Normal file
@@ -0,0 +1,36 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"os"
|
||||
|
||||
"net/http"
|
||||
|
||||
"github.com/tencentyun/cos-go-sdk-v5"
|
||||
"github.com/tencentyun/cos-go-sdk-v5/debug"
|
||||
)
|
||||
|
||||
func main() {
|
||||
c := cos.NewClient(nil, &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,
|
||||
},
|
||||
},
|
||||
})
|
||||
|
||||
s, _, err := c.Service.Get(context.Background())
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
for _, b := range s.Buckets {
|
||||
fmt.Printf("%#v\n", b)
|
||||
}
|
||||
}
|
||||
101
example/sts/sts.go
Normal file
101
example/sts/sts.go
Normal file
@@ -0,0 +1,101 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"github.com/QcloudApi/qcloud_sign_golang"
|
||||
"github.com/tencentyun/cos-go-sdk-v5"
|
||||
"github.com/tencentyun/cos-go-sdk-v5/debug"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"strings"
|
||||
)
|
||||
|
||||
// Use Qcloud api github.com/QcloudApi/qcloud_sign_golang
|
||||
// doc https://cloud.tencent.com/document/product/436/14048
|
||||
type Credent struct {
|
||||
SessionToken string `json:"sessionToken"`
|
||||
TmpSecretID string `json:"tmpSecretId"`
|
||||
TmpSecretKey string `json:"tmpSecretKey"`
|
||||
}
|
||||
|
||||
// Data data in sts response body
|
||||
type Data struct {
|
||||
Credentials Credent `json:"credentials"`
|
||||
}
|
||||
|
||||
// Response sts response body
|
||||
// In qcloud_sign_golang this response only return ak, sk and token
|
||||
type Response struct {
|
||||
Dat Data `json:"data"`
|
||||
}
|
||||
|
||||
func main() {
|
||||
// 替换实际的 SecretId 和 SecretKey
|
||||
secretID := "ak"
|
||||
secretKey := "sk"
|
||||
|
||||
// 配置
|
||||
config := map[string]interface{}{"secretId": secretID, "secretKey": secretKey, "debug": false}
|
||||
|
||||
// 请求参数
|
||||
params := map[string]interface{}{"Region": "gz", "Action": "GetFederationToken", "name": "alantong", "policy": "{\"statement\": [{\"action\": [\"name/cos:GetObject\",\"name/cos:PutObject\"],\"effect\": \"allow\",\"resource\":[\"qcs::cos:ap-guangzhou:uid/1253960454:prefix//1253960454/alangz/*\"]}],\"version\": \"2.0\"}"}
|
||||
|
||||
// 发送请求
|
||||
retData, err := QcloudApi.SendRequest("sts", params, config)
|
||||
if err != nil {
|
||||
fmt.Print("Error.", err)
|
||||
return
|
||||
}
|
||||
r := &Response{}
|
||||
err = json.Unmarshal([]byte(retData), r)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
//获取临时ak、sk、token
|
||||
tAk := r.Dat.Credentials.TmpSecretID
|
||||
tSk := r.Dat.Credentials.TmpSecretKey
|
||||
token := r.Dat.Credentials.SessionToken
|
||||
|
||||
u, _ := url.Parse("https://alangz-1253960454.cos.ap-guangzhou.myqcloud.com")
|
||||
b := &cos.BaseURL{BucketURL: u}
|
||||
c := cos.NewClient(b, &http.Client{
|
||||
Transport: &cos.AuthorizationTransport{
|
||||
SecretID: tAk,
|
||||
SecretKey: tSk,
|
||||
SessionToken: token,
|
||||
Transport: &debug.DebugRequestTransport{
|
||||
RequestHeader: true,
|
||||
RequestBody: true,
|
||||
ResponseHeader: true,
|
||||
ResponseBody: true,
|
||||
},
|
||||
},
|
||||
})
|
||||
|
||||
name := "test/objectPut.go"
|
||||
f := strings.NewReader("test")
|
||||
|
||||
_, err = c.Object.Put(context.Background(), name, f, nil)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
name = "test/put_option.go"
|
||||
f = strings.NewReader("test xxx")
|
||||
opt := &cos.ObjectPutOptions{
|
||||
ObjectPutHeaderOptions: &cos.ObjectPutHeaderOptions{
|
||||
ContentType: "text/html",
|
||||
},
|
||||
ACLHeaderOptions: &cos.ACLHeaderOptions{
|
||||
//XCosACL: "public-read",
|
||||
XCosACL: "private",
|
||||
},
|
||||
}
|
||||
_, err = c.Object.Put(context.Background(), name, f, opt)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
57
example/test.sh
Normal file
57
example/test.sh
Normal file
@@ -0,0 +1,57 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
function run() {
|
||||
go run "$@"
|
||||
|
||||
if [ $? -ne 0 ]
|
||||
then
|
||||
exit 3
|
||||
fi
|
||||
}
|
||||
|
||||
echo '###### service ####'
|
||||
run ./service/get.go
|
||||
|
||||
|
||||
echo '##### bucket ####'
|
||||
|
||||
run ./bucket/delete.go
|
||||
run ./bucket/put.go
|
||||
run ./bucket/putACL.go
|
||||
run ./bucket/putCORS.go
|
||||
run ./bucket/putLifecycle.go
|
||||
run ./bucket/putTagging.go
|
||||
run ./bucket/get.go
|
||||
run ./bucket/getACL.go
|
||||
run ./bucket/getCORS.go
|
||||
run ./bucket/getLifecycle.go
|
||||
run ./bucket/getTagging.go
|
||||
run ./bucket/getLocation.go
|
||||
run ./bucket/head.go
|
||||
run ./bucket/listMultipartUploads.go
|
||||
run ./bucket/delete.go
|
||||
run ./bucket/deleteCORS.go
|
||||
run ./bucket/deleteLifecycle.go
|
||||
run ./bucket/deleteTagging.go
|
||||
|
||||
|
||||
echo '##### object ####'
|
||||
|
||||
run ./bucket/putCORS.go
|
||||
run ./object/put.go
|
||||
run ./object/uploadFile.go
|
||||
run ./object/putACL.go
|
||||
run ./object/append.go
|
||||
run ./object/get.go
|
||||
run ./object/head.go
|
||||
run ./object/getAnonymous.go
|
||||
run ./object/getACL.go
|
||||
run ./object/listParts.go
|
||||
run ./object/options.go
|
||||
run ./object/initiateMultipartUpload.go
|
||||
run ./object/uploadPart.go
|
||||
run ./object/completeMultipartUpload.go
|
||||
run ./object/abortMultipartUpload.go
|
||||
run ./object/delete.go
|
||||
run ./object/deleteMultiple.go
|
||||
run ./object/copy.go
|
||||
Reference in New Issue
Block a user