jojoliang
3 years ago
7 changed files with 139 additions and 137 deletions
-
24bucket_domain.go
-
51bucket_domain_test.go
-
71example/bucket/domain.go
-
35example/bucket/getDomain.go
-
42example/bucket/putDomain.go
-
27object.go
-
26object_test.go
@ -0,0 +1,71 @@ |
|||
package main |
|||
|
|||
import ( |
|||
"context" |
|||
"fmt" |
|||
"net/http" |
|||
"net/url" |
|||
"os" |
|||
|
|||
"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.BucketPutDomainOptions{ |
|||
Rules: []cos.BucketDomainRule{ |
|||
{ |
|||
Status: "ENABLED", |
|||
Name: "www.qq.com", |
|||
Type: "REST", |
|||
ForcedReplacement: "CNAME", |
|||
}, |
|||
}, |
|||
} |
|||
|
|||
_, err := c.Bucket.PutDomain(context.Background(), opt) |
|||
log_status(err) |
|||
|
|||
res, _, err := c.Bucket.GetDomain(context.Background()) |
|||
log_status(err) |
|||
fmt.Printf("%+v\n", res) |
|||
|
|||
_, err = c.Bucket.DeleteDomain(context.Background()) |
|||
log_status(err) |
|||
} |
@ -1,35 +0,0 @@ |
|||
package main |
|||
|
|||
import ( |
|||
"context" |
|||
"net/http" |
|||
"net/url" |
|||
"os" |
|||
|
|||
"github.com/tencentyun/cos-go-sdk-v5" |
|||
"github.com/tencentyun/cos-go-sdk-v5/debug" |
|||
) |
|||
|
|||
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, |
|||
}, |
|||
}, |
|||
}) |
|||
|
|||
_, _, err := c.Bucket.GetDomain(context.Background()) |
|||
if err != nil { |
|||
panic(err) |
|||
} |
|||
} |
@ -1,42 +0,0 @@ |
|||
package main |
|||
|
|||
import ( |
|||
"context" |
|||
"net/http" |
|||
"net/url" |
|||
"os" |
|||
|
|||
"github.com/tencentyun/cos-go-sdk-v5" |
|||
"github.com/tencentyun/cos-go-sdk-v5/debug" |
|||
) |
|||
|
|||
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.BucketPutDomainOptions{ |
|||
Status: "ENABLED", |
|||
Name: "www.abc.com", |
|||
Type: "REST", |
|||
ForcedReplacement: "CNAME", |
|||
} |
|||
|
|||
_, err := c.Bucket.PutDomain(context.Background(), opt) |
|||
if err != nil { |
|||
panic(err) |
|||
} |
|||
} |
Write
Preview
Loading…
Cancel
Save
Reference in new issue