You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

39 lines
777 B

5 years ago
  1. package main
  2. import (
  3. "context"
  4. "encoding/json"
  5. "fmt"
  6. "net/http"
  7. "net/url"
  8. "os"
  9. "github.com/tencentyun/cos-go-sdk-v5"
  10. "github.com/tencentyun/cos-go-sdk-v5/debug"
  11. )
  12. func main() {
  13. u, _ := url.Parse("https://test-1259654469.cos.ap-guangzhou.myqcloud.com")
  14. b := &cos.BaseURL{
  15. BucketURL: u,
  16. }
  17. c := cos.NewClient(b, &http.Client{
  18. Transport: &cos.AuthorizationTransport{
  19. SecretID: os.Getenv("COS_SECRETID"),
  20. SecretKey: os.Getenv("COS_SECRETKEY"),
  21. Transport: &debug.DebugRequestTransport{
  22. RequestHeader: true,
  23. RequestBody: true,
  24. ResponseHeader: true,
  25. ResponseBody: true,
  26. },
  27. },
  28. })
  29. res, _, err := c.Bucket.GetPolicy(context.Background())
  30. if err != nil {
  31. panic(err)
  32. }
  33. bs, err := json.Marshal(res)
  34. fmt.Println(string(bs))
  35. }