bucket_qosInfo.go 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. package sample
  2. import (
  3. "fmt"
  4. "github.com/aliyun/aliyun-oss-go-sdk/oss"
  5. )
  6. // BucketQoSInfoSample shows how to set, get and delete the bucket QoS configuration
  7. func BucketQoSInfoSample() {
  8. // New client
  9. client, err := oss.New(endpoint, accessID, accessKey)
  10. if err != nil {
  11. HandleError(err)
  12. }
  13. // Create the bucket with default parameters
  14. err = client.CreateBucket(bucketName)
  15. if err != nil {
  16. HandleError(err)
  17. }
  18. // Initial QoS Configuration
  19. five := 5
  20. four := 4
  21. totalQps := 200
  22. qosConf := oss.BucketQoSConfiguration{
  23. TotalUploadBandwidth: &five,
  24. IntranetUploadBandwidth: &four,
  25. ExtranetUploadBandwidth: &four,
  26. TotalDownloadBandwidth: &four,
  27. IntranetDownloadBandwidth: &four,
  28. ExtranetDownloadBandwidth: &four,
  29. TotalQPS: &totalQps,
  30. IntranetQPS: &totalQps,
  31. ExtranetQPS: &totalQps,
  32. }
  33. // Set Qos Info
  34. err = client.SetBucketQoSInfo(bucketName, qosConf)
  35. if err != nil {
  36. HandleError(err)
  37. }
  38. // Get Qos Info
  39. ret, err := client.GetBucketQosInfo(bucketName)
  40. if err != nil {
  41. HandleError(err)
  42. }
  43. fmt.Printf("Bucket QoSInfo\n TotalUploadBandwidth: %d\n IntranetUploadBandwidth: %d\n ExtranetUploadBandwidth: %d\n",
  44. *ret.TotalUploadBandwidth, *ret.IntranetUploadBandwidth, *ret.ExtranetUploadBandwidth)
  45. // Delete QosInfo
  46. err = client.DeleteBucketQosInfo(bucketName)
  47. if err != nil {
  48. HandleError(err)
  49. }
  50. // Delete bucket
  51. err = client.DeleteBucket(bucketName)
  52. if err != nil {
  53. HandleError(err)
  54. }
  55. fmt.Println("BucketPolicySample completed")
  56. }