Browse Source
Merge pull request #78 from agin719/common-dev
Merge pull request #78 from agin719/common-dev
add GetBucketObjectVersions & update tips when failedtags/v0.7.6 v0.7.6
committed by
GitHub
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
32 changed files with 986 additions and 180 deletions
-
58bucket.go
-
105bucket_test.go
-
2cos.go
-
9costesting/ci_test.go
-
38example/bucket/getLogging.go
-
64example/bucket/getObjectVersion.go
-
23example/object/MultiUpload.go
-
27example/object/abortMultipartUpload.go
-
12example/object/ci_put.go
-
35example/object/completeMultipartUpload.go
-
36example/object/copy.go
-
31example/object/copyPart.go
-
24example/object/delete.go
-
27example/object/deleteMultiple.go
-
42example/object/get.go
-
25example/object/getACL.go
-
24example/object/getAnonymous.go
-
32example/object/getByPresignedURL.go
-
24example/object/head.go
-
23example/object/initiateMultipartUpload.go
-
31example/object/listParts.go
-
26example/object/options.go
-
44example/object/presigned_url_with_token.go
-
35example/object/put.go
-
28example/object/putACL.go
-
24example/object/restore.go
-
81example/object/sse_c.go
-
75example/object/sse_cos.go
-
23example/object/upload.go
-
29example/object/uploadFile.go
-
27example/object/uploadPart.go
@ -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://bj-1259654469.cos.ap-beijing.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.GetLogging(context.Background()) |
||||
|
if err != nil { |
||||
|
panic(err) |
||||
|
} |
||||
|
fmt.Printf("%+v\n", v.LoggingEnabled) |
||||
|
} |
@ -0,0 +1,64 @@ |
|||||
|
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 log_status(err error) { |
||||
|
if err == nil { |
||||
|
return |
||||
|
} |
||||
|
if cos.IsNotFoundError(err) { |
||||
|
// WARN
|
||||
|
fmt.Println("WARN: Resource is not existed") |
||||
|
} else if e, ok := cos.IsCOSError(err); ok { |
||||
|
fmt.Printf("ERROR: Code: %v\n", e.Code) |
||||
|
fmt.Printf("ERROR: Message: %v\n", e.Message) |
||||
|
fmt.Printf("ERROR: Resource: %v\n", e.Resource) |
||||
|
fmt.Printf("ERROR: RequestId: %v\n", e.RequestID) |
||||
|
// ERROR
|
||||
|
} else { |
||||
|
fmt.Printf("ERROR: %v\n", err) |
||||
|
// ERROR
|
||||
|
} |
||||
|
} |
||||
|
|
||||
|
func main() { |
||||
|
u, _ := url.Parse("https://test-1259654469.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.BucketGetObjectVersionsOptions { |
||||
|
Delimiter: "/", |
||||
|
MaxKeys: 1, |
||||
|
} |
||||
|
v, _, err := c.Bucket.GetObjectVersions(context.Background(), opt) |
||||
|
log_status(err) |
||||
|
|
||||
|
for _, c := range v.Version { |
||||
|
fmt.Printf("%v, %v, %v\n", c.Key, c.Size, c.IsLatest) |
||||
|
} |
||||
|
|
||||
|
} |
@ -0,0 +1,44 @@ |
|||||
|
package main |
||||
|
|
||||
|
import ( |
||||
|
"context" |
||||
|
"fmt" |
||||
|
"net/http" |
||||
|
"net/url" |
||||
|
"os" |
||||
|
"time" |
||||
|
|
||||
|
"github.com/tencentyun/cos-go-sdk-v5" |
||||
|
) |
||||
|
|
||||
|
type URLToken struct { |
||||
|
SessionToken string `url:"x-cos-security-token,omitempty" header:"-"` |
||||
|
} |
||||
|
|
||||
|
func main() { |
||||
|
// 替换成您的临时密钥
|
||||
|
tak := os.Getenv("COS_SECRETID") |
||||
|
tsk := os.Getenv("COS_SECRETKEY") |
||||
|
token := &URLToken{ |
||||
|
SessionToken: "<token>", |
||||
|
} |
||||
|
u, _ := url.Parse("https://test-1259654469.cos.ap-guangzhou.myqcloud.com") |
||||
|
b := &cos.BaseURL{BucketURL: u} |
||||
|
c := cos.NewClient(b, &http.Client{}) |
||||
|
|
||||
|
name := "exampleobject" |
||||
|
ctx := context.Background() |
||||
|
|
||||
|
// Get presigned
|
||||
|
presignedURL, err := c.Object.GetPresignedURL(ctx, http.MethodGet, name, tak, tsk, time.Hour, token) |
||||
|
if err != nil { |
||||
|
fmt.Printf("Error: %v\n", err) |
||||
|
return |
||||
|
} |
||||
|
// Get object by presinged url
|
||||
|
_, err = http.Get(presignedURL.String()) |
||||
|
if err != nil { |
||||
|
fmt.Printf("Error: %v\n", err) |
||||
|
} |
||||
|
fmt.Println(presignedURL.String()) |
||||
|
} |
@ -0,0 +1,81 @@ |
|||||
|
package main |
||||
|
|
||||
|
import ( |
||||
|
"context" |
||||
|
"errors" |
||||
|
"fmt" |
||||
|
"io/ioutil" |
||||
|
"net/http" |
||||
|
"net/url" |
||||
|
"os" |
||||
|
"strings" |
||||
|
|
||||
|
"github.com/tencentyun/cos-go-sdk-v5" |
||||
|
"github.com/tencentyun/cos-go-sdk-v5/debug" |
||||
|
) |
||||
|
|
||||
|
func log_status(err error) { |
||||
|
if err == nil { |
||||
|
return |
||||
|
} |
||||
|
if cos.IsNotFoundError(err) { |
||||
|
// WARN
|
||||
|
fmt.Println("WARN: Resource is not existed") |
||||
|
} else if e, ok := cos.IsCOSError(err); ok { |
||||
|
fmt.Printf("ERROR: Code: %v\n", e.Code) |
||||
|
fmt.Printf("ERROR: Message: %v\n", e.Message) |
||||
|
fmt.Printf("ERROR: Resource: %v\n", e.Resource) |
||||
|
fmt.Printf("ERROR: RequestId: %v\n", e.RequestID) |
||||
|
// ERROR
|
||||
|
} else { |
||||
|
fmt.Printf("ERROR: %v\n", err) |
||||
|
// ERROR
|
||||
|
} |
||||
|
} |
||||
|
|
||||
|
func main() { |
||||
|
u, _ := url.Parse("https://testcd-1259654469.cos.ap-chengdu.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, |
||||
|
// Notice when put a large file and set need the request body, might happend out of memory error.
|
||||
|
RequestBody: false, |
||||
|
ResponseHeader: true, |
||||
|
ResponseBody: true, |
||||
|
}, |
||||
|
}, |
||||
|
}) |
||||
|
opt := &cos.ObjectPutOptions{ |
||||
|
ObjectPutHeaderOptions: &cos.ObjectPutHeaderOptions{ |
||||
|
ContentType: "text/html", |
||||
|
XCosSSECustomerAglo: "AES256", |
||||
|
XCosSSECustomerKey: "MDEyMzQ1Njc4OUFCQ0RFRjAxMjM0NTY3ODlBQkNERUY=", |
||||
|
XCosSSECustomerKeyMD5: "U5L61r7jcwdNvT7frmUG8g==", |
||||
|
}, |
||||
|
ACLHeaderOptions: &cos.ACLHeaderOptions{}, |
||||
|
} |
||||
|
name := "PutFromGoWithSSE-C" |
||||
|
content := "Put Object From Go With SSE-C" |
||||
|
f := strings.NewReader(content) |
||||
|
_, err := c.Object.Put(context.Background(), name, f, opt) |
||||
|
log_status(err) |
||||
|
|
||||
|
getopt := &cos.ObjectGetOptions{ |
||||
|
XCosSSECustomerAglo: "AES256", |
||||
|
XCosSSECustomerKey: "MDEyMzQ1Njc4OUFCQ0RFRjAxMjM0NTY3ODlBQkNERUY=", |
||||
|
XCosSSECustomerKeyMD5: "U5L61r7jcwdNvT7frmUG8g==", |
||||
|
} |
||||
|
var resp *cos.Response |
||||
|
resp, err = c.Object.Get(context.Background(), name, getopt) |
||||
|
log_status(err) |
||||
|
|
||||
|
bodyBytes, _ := ioutil.ReadAll(resp.Body) |
||||
|
bodyContent := string(bodyBytes) |
||||
|
if bodyContent != content { |
||||
|
log_status(errors.New("Content inconsistency")) |
||||
|
} |
||||
|
} |
@ -0,0 +1,75 @@ |
|||||
|
package main |
||||
|
|
||||
|
import ( |
||||
|
"context" |
||||
|
"errors" |
||||
|
"fmt" |
||||
|
"io/ioutil" |
||||
|
"net/http" |
||||
|
"net/url" |
||||
|
"os" |
||||
|
"strings" |
||||
|
|
||||
|
"github.com/tencentyun/cos-go-sdk-v5" |
||||
|
"github.com/tencentyun/cos-go-sdk-v5/debug" |
||||
|
) |
||||
|
|
||||
|
func log_status(err error) { |
||||
|
if err == nil { |
||||
|
return |
||||
|
} |
||||
|
if cos.IsNotFoundError(err) { |
||||
|
// WARN
|
||||
|
fmt.Println("WARN: Resource is not existed") |
||||
|
} else if e, ok := cos.IsCOSError(err); ok { |
||||
|
fmt.Printf("ERROR: Code: %v\n", e.Code) |
||||
|
fmt.Printf("ERROR: Message: %v\n", e.Message) |
||||
|
fmt.Printf("ERROR: Resource: %v\n", e.Resource) |
||||
|
fmt.Printf("ERROR: RequestId: %v\n", e.RequestID) |
||||
|
// ERROR
|
||||
|
} else { |
||||
|
fmt.Printf("ERROR: %v\n", err) |
||||
|
// ERROR
|
||||
|
} |
||||
|
} |
||||
|
|
||||
|
func main() { |
||||
|
u, _ := url.Parse("https://test-1259654469.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, |
||||
|
// Notice when put a large file and set need the request body, might happend out of memory error.
|
||||
|
RequestBody: false, |
||||
|
ResponseHeader: true, |
||||
|
ResponseBody: true, |
||||
|
}, |
||||
|
}, |
||||
|
}) |
||||
|
opt := &cos.ObjectPutOptions{ |
||||
|
ObjectPutHeaderOptions: &cos.ObjectPutHeaderOptions{ |
||||
|
ContentType: "text/html", |
||||
|
XCosServerSideEncryption: "AES256", |
||||
|
}, |
||||
|
ACLHeaderOptions: &cos.ACLHeaderOptions{}, |
||||
|
} |
||||
|
name := "PutFromGoWithSSE-COS" |
||||
|
content := "Put Object From Go With SSE-COS" |
||||
|
f := strings.NewReader(content) |
||||
|
_, err := c.Object.Put(context.Background(), name, f, opt) |
||||
|
log_status(err) |
||||
|
|
||||
|
getopt := &cos.ObjectGetOptions{} |
||||
|
var resp *cos.Response |
||||
|
resp, err = c.Object.Get(context.Background(), name, getopt) |
||||
|
log_status(err) |
||||
|
|
||||
|
bodyBytes, _ := ioutil.ReadAll(resp.Body) |
||||
|
bodyContent := string(bodyBytes) |
||||
|
if bodyContent != content { |
||||
|
log_status(errors.New("Content inconsistency")) |
||||
|
} |
||||
|
} |
Write
Preview
Loading…
Cancel
Save
Reference in new issue