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.

71 lines
1.7 KiB

  1. package main
  2. import (
  3. "context"
  4. "fmt"
  5. "net/http"
  6. "net/url"
  7. "os"
  8. "time"
  9. "github.com/tencentyun/cos-go-sdk-v5"
  10. "github.com/tencentyun/cos-go-sdk-v5/debug"
  11. )
  12. func log_status(err error) {
  13. if err == nil {
  14. return
  15. }
  16. if cos.IsNotFoundError(err) {
  17. // WARN
  18. fmt.Println("WARN: Resource is not existed")
  19. } else if e, ok := cos.IsCOSError(err); ok {
  20. fmt.Printf("ERROR: Code: %v\n", e.Code)
  21. fmt.Printf("ERROR: Message: %v\n", e.Message)
  22. fmt.Printf("ERROR: Resource: %v\n", e.Resource)
  23. fmt.Printf("ERROR: RequestId: %v\n", e.RequestID)
  24. // ERROR
  25. } else {
  26. fmt.Printf("ERROR: %v\n", err)
  27. // ERROR
  28. }
  29. }
  30. func main() {
  31. bu, _ := url.Parse("https://test-1259654469.cos.ap-guangzhou.myqcloud.com")
  32. cu, _ := url.Parse("https://test-1259654469.ci.ap-guangzhou.myqcloud.com")
  33. b := &cos.BaseURL{BucketURL: bu, CIURL: cu}
  34. c := cos.NewClient(b, &http.Client{
  35. Transport: &cos.AuthorizationTransport{
  36. SecretID: os.Getenv("COS_SECRETID"),
  37. SecretKey: os.Getenv("COS_SECRETKEY"),
  38. Transport: &debug.DebugRequestTransport{
  39. RequestHeader: true,
  40. RequestBody: true,
  41. ResponseHeader: true,
  42. ResponseBody: true,
  43. },
  44. },
  45. })
  46. opt := &cos.PutVideoAuditingJobOptions{
  47. InputObject: "demo.mp4",
  48. Conf: &cos.VideoAuditingJobConf{
  49. DetectType: "Porn,Terrorism,Politics,Ads",
  50. Snapshot: &cos.PutVideoAuditingJobSnapshot{
  51. Mode: "Interval",
  52. Start: 0.5,
  53. TimeInterval: 50.5,
  54. Count: 100,
  55. },
  56. },
  57. }
  58. res, _, err := c.CI.PutVideoAuditingJob(context.Background(), opt)
  59. log_status(err)
  60. fmt.Printf("%+v\n", res)
  61. time.Sleep(3 * time.Second)
  62. res2, _, err := c.CI.GetVideoAuditingJob(context.Background(), res.JobsDetail.JobId)
  63. log_status(err)
  64. fmt.Printf("%+v\n", res2)
  65. }