Manage resource pool QoS (Go SDK V2)
Updated at:
This topic describes how to use Go SDK V2 to manage and configure resource pool Quality of Service (QoS).
Notes
-
The sample code in this topic uses the China (Hangzhou) region as an example. The region ID is
cn-hangzhou. By default, a public Endpoint is used. If you want to access OSS from other Alibaba Cloud products in the same region as OSS, use a private network Endpoint. For more information about the mappings between OSS regions and Endpoints, see Regions and Endpoints.
Bucket bandwidth management
Set throttling for buckets in a resource pool
package main
import (
"bytes"
"context"
"crypto/md5"
"encoding/base64"
"fmt"
"os"
"github.com/aliyun/alibabacloud-oss-go-sdk-v2/oss"
"github.com/aliyun/alibabacloud-oss-go-sdk-v2/oss/credentials"
)
func main() {
// Specify the region where the bucket is located. For example, set the region to cn-hangzhou for China (Hangzhou).
var region = "cn-hangzhou"
// Load the default configurations and set the credential provider and region.
cfg := oss.LoadDefaultConfig().
WithCredentialsProvider(credentials.NewEnvironmentVariableCredentialsProvider()).
WithRegion(region)
// Create an OSS client.
client := oss.NewClient(cfg)
// Define the bucket name.
bucketName := "examplebucket"
// Read the content of the QoS configuration file.
qosConf, err := os.ReadFile("qos.xml")
if err != nil {
// If an error occurs while reading the QoS configuration file, print the error message and exit the program.
fmt.Printf("failed to read qos.xml: %v\n", err)
os.Exit(1)
}
// Calculate the MD5 hash of the input data and convert it to a Base64-encoded string.
calcMd5 := func(input []byte) string {
if len(input) == 0 {
return "1B2M2Y8AsgTpgAmY7PhCfg=="
}
h := md5.New()
h.Write(input)
return base64.StdEncoding.EncodeToString(h.Sum(nil))
}
// Create the input parameters for the operation, including the action, method type, and other parameters.
input := &oss.OperationInput{
OpName: "PutBucketQoSInfo", // The action.
Method: "PUT", // The HTTP method.
Parameters: map[string]string{
"qosInfo": "", // QoS-related parameters.
},
Headers: map[string]string{
"Content-MD5": calcMd5(qosConf), // Set the MD5 hash of the request body for data integrity validation.
},
Body: bytes.NewReader(qosConf), // The request body, which contains the QoS configuration content.
Bucket: oss.Ptr(bucketName), // The bucket name.
}
// Execute the operation and receive the response or an error.
res, err := client.InvokeOperation(context.TODO(), input)
if err != nil {
// If an error occurs, print the error message and exit the program.
fmt.Printf("invoke operation got error: %v\n", err)
os.Exit(1)
}
// Print the operation result.
fmt.Println("The result of PutBucketQoSInfo:", res.Status)
}
Get bucket throttling configurations
package main
import (
"context"
"fmt"
"io"
"os"
"github.com/aliyun/alibabacloud-oss-go-sdk-v2/oss"
"github.com/aliyun/alibabacloud-oss-go-sdk-v2/oss/credentials"
)
func main() {
// Specify the region where the bucket is located. For example, set the region to cn-hangzhou for China (Hangzhou).
var region = "cn-hangzhou"
// Load the default configurations and set the credential provider and region.
cfg := oss.LoadDefaultConfig().
WithCredentialsProvider(credentials.NewEnvironmentVariableCredentialsProvider()).
WithRegion(region)
// Create an OSS client.
client := oss.NewClient(cfg)
// Define the bucket name.
bucketName := "examplebucket"
// Create the input parameters for the operation, including the action, method type, and other parameters.
input := &oss.OperationInput{
OpName: "GetBucketQoSInfo", // The action.
Method: "GET", // The HTTP method.
Parameters: map[string]string{
"qosInfo": "", // QoS-related parameters.
},
Headers: map[string]string{}, // The HTTP headers.
Body: nil, // The request body. It is usually empty for a GET request.
Bucket: oss.Ptr(bucketName), // The bucket name.
}
// Execute the operation and receive the response or an error.
res, err := client.InvokeOperation(context.TODO(), input)
if err != nil {
// If an error occurs, print the error message and exit the program.
fmt.Printf("invoke operation got error: %v\n", err)
os.Exit(1)
}
// Read the response body.
body, err := io.ReadAll(res.Body)
if err != nil {
// If an error occurs while reading the response body, print the error message and exit the program.
fmt.Printf("failed to read response body: %v\n", err)
os.Exit(1)
}
// Close the response body to ensure that resources are released.
if res.Body != nil {
res.Body.Close()
}
// Print the operation result.
fmt.Println("The result of GetBucketQoSInfo:", string(body))
}
Delete the throttling configurations of a specified bucket in a resource pool
package main
import (
"context"
"fmt"
"os"
"github.com/aliyun/alibabacloud-oss-go-sdk-v2/oss"
"github.com/aliyun/alibabacloud-oss-go-sdk-v2/oss/credentials"
)
func main() {
// Specify the region where the bucket is located. For example, set the region to cn-hangzhou for China (Hangzhou).
var region = "cn-hangzhou"
// Load the default configurations and set the credential provider and region.
cfg := oss.LoadDefaultConfig().
WithCredentialsProvider(credentials.NewEnvironmentVariableCredentialsProvider()).
WithRegion(region)
// Create an OSS client.
client := oss.NewClient(cfg)
// Define the bucket name.
bucketName := "examplebucket"
// Create the input parameters for the operation, including the action, method type, and other parameters.
input := &oss.OperationInput{
OpName: "DeleteBucketQoSInfo", // The action.
Method: "DELETE", // The HTTP method.
Parameters: map[string]string{
"qosInfo": "", // QoS-related parameters.
},
Headers: map[string]string{}, // The HTTP headers.
Body: nil, // The request body. It is usually empty for a DELETE request.
Bucket: oss.Ptr(bucketName), // The bucket name.
}
// Execute the operation and receive the response or an error.
res, err := client.InvokeOperation(context.TODO(), input)
if err != nil {
// If an error occurs, print the error message and exit the program.
fmt.Printf("invoke operation got error: %v\n", err)
os.Exit(1)
}
// Print the operation result.
fmt.Println("The result of DeleteBucketQoSInfo:", res.Status)
}
Bandwidth management for different requesters at the bucket level
Set throttling for a requester at the bucket level
package main
import (
"bytes"
"context"
"crypto/md5"
"encoding/base64"
"fmt"
"os"
"github.com/aliyun/alibabacloud-oss-go-sdk-v2/oss"
"github.com/aliyun/alibabacloud-oss-go-sdk-v2/oss/credentials"
)
func main() {
// Specify the region where the bucket is located. For example, set the region to cn-hangzhou for China (Hangzhou).
var region = "cn-hangzhou"
// Load the default configurations and set the credential provider and region.
cfg := oss.LoadDefaultConfig().
WithCredentialsProvider(credentials.NewEnvironmentVariableCredentialsProvider()).
WithRegion(region)
// Create an OSS client.
client := oss.NewClient(cfg)
// Define the bucket name and requester ID.
bucketName := "examplebucket"
requester := "2598732222222xxxx"
// Read the content of the QoS configuration file.
qosConf, err := os.ReadFile("qos.xml")
if err != nil {
// If an error occurs while reading the QoS configuration file, print the error message and exit the program.
fmt.Printf("failed to read qos.xml: %v\n", err)
os.Exit(1)
}
// Calculate the MD5 hash of the input data and convert it to a Base64-encoded string.
calcMd5 := func(input []byte) string {
if len(input) == 0 {
return "1B2M2Y8AsgTpgAmY7PhCfg=="
}
h := md5.New()
h.Write(input)
return base64.StdEncoding.EncodeToString(h.Sum(nil))
}
// Create the input parameters for the operation, including the action, method type, and other parameters.
input := &oss.OperationInput{
OpName: "PutBucketRequesterQoSInfo", // The action must match the actual operation.
Method: "PUT", // The HTTP method.
Parameters: map[string]string{
"requesterQosInfo": "", // Requester QoS-related parameters.
"qosRequester": requester, // The requester ID.
},
Headers: map[string]string{
"Content-MD5": calcMd5(qosConf), // Set the MD5 hash of the request body for data integrity validation.
},
Body: bytes.NewReader(qosConf), // The request body, which contains the QoS configuration content.
Bucket: oss.Ptr(bucketName), // The bucket name.
}
// Execute the operation and receive the response or an error.
res, err := client.InvokeOperation(context.TODO(), input)
if err != nil {
// If an error occurs, print the error message and exit the program.
fmt.Printf("invoke operation got error: %v\n", err)
os.Exit(1)
}
// Print the operation result.
fmt.Println("The result of PutBucketRequesterQoSInfo:", res.Status)
}
Get the throttling configurations for a specified requester at the bucket level
package main
import (
"context"
"fmt"
"io"
"os"
"github.com/aliyun/alibabacloud-oss-go-sdk-v2/oss"
"github.com/aliyun/alibabacloud-oss-go-sdk-v2/oss/credentials"
)
func main() {
// Specify the region where the bucket is located. For example, set the region to cn-hangzhou for China (Hangzhou).
var region = "cn-hangzhou"
// Load the default configurations and set the credential provider and region.
cfg := oss.LoadDefaultConfig().
WithCredentialsProvider(credentials.NewEnvironmentVariableCredentialsProvider()).
WithRegion(region)
// Create an OSS client.
client := oss.NewClient(cfg)
// Define the bucket name and requester ID.
bucketName := "examplebucket"
requester := "2598732222222xxxx"
// Create the input parameters for the operation, including the action, method type, and other parameters.
input := &oss.OperationInput{
OpName: "GetBucketRequesterQoSInfo", // The action.
Method: "GET", // The HTTP method.
Parameters: map[string]string{
"requesterQosInfo": "", // Requester QoS-related parameters.
"qosRequester": requester, // The requester ID.
},
Headers: map[string]string{}, // The HTTP headers.
Body: nil, // The request body. It is usually empty for a GET request.
Bucket: oss.Ptr(bucketName), // The bucket name.
}
// Execute the operation and receive the response or an error.
res, err := client.InvokeOperation(context.TODO(), input)
if err != nil {
// If an error occurs, print the error message and exit the program.
fmt.Printf("invoke operation got error: %v\n", err)
os.Exit(1)
}
// Read the response body.
body, err := io.ReadAll(res.Body)
if err != nil {
// If an error occurs while reading the response body, print the error message and exit the program.
fmt.Printf("failed to read response body: %v\n", err)
os.Exit(1)
}
// Close the response body to ensure that resources are released.
if res.Body != nil {
res.Body.Close()
}
// Print the operation result.
fmt.Println("The result of GetBucketRequesterQoSInfo:", string(body))
}
Get the throttling configurations for all requesters at the bucket level
package main
import (
"context"
"fmt"
"io"
"os"
"github.com/aliyun/alibabacloud-oss-go-sdk-v2/oss"
"github.com/aliyun/alibabacloud-oss-go-sdk-v2/oss/credentials"
)
func main() {
// Specify the region where the bucket is located. For example, set the region to cn-hangzhou for China (Hangzhou).
var region = "cn-hangzhou"
// Load the default configurations and set the credential provider and region.
cfg := oss.LoadDefaultConfig().
WithCredentialsProvider(credentials.NewEnvironmentVariableCredentialsProvider()).
WithRegion(region)
// Create an OSS client.
client := oss.NewClient(cfg)
// Define the bucket name.
bucketName := "examplebucket"
// Create the input parameters for the operation, including the action, method type, and other parameters.
input := &oss.OperationInput{
OpName: "ListBucketRequesterQoSInfos", // The action.
Method: "GET", // The HTTP method.
Parameters: map[string]string{
"requesterQosInfo": "", // Requester QoS-related parameters.
// Optional parameters:
// "continuation-token": "25987311111111xxxx", // The continuation token for paging.
// "max-keys": "1", // The maximum number of entries to return.
},
Headers: map[string]string{}, // The HTTP headers.
Body: nil, // The request body. It is usually empty for a GET request.
Bucket: oss.Ptr(bucketName), // The bucket name.
}
// Execute the operation and receive the response or an error.
res, err := client.InvokeOperation(context.TODO(), input)
if err != nil {
// If an error occurs, print the error message and exit the program.
fmt.Printf("invoke operation got error: %v\n", err)
os.Exit(1)
}
// Read the response body.
body, err := io.ReadAll(res.Body)
if err != nil {
// If an error occurs while reading the response body, print the error message and exit the program.
fmt.Printf("failed to read response body: %v\n", err)
os.Exit(1)
}
// Close the response body to ensure that resources are released.
if res.Body != nil {
res.Body.Close()
}
// Print the operation result.
fmt.Println("The result of ListBucketRequesterQoSInfos:", string(body))
}
Delete the throttling configurations for a requester of a bucket
package main
import (
"context"
"fmt"
"os"
"github.com/aliyun/alibabacloud-oss-go-sdk-v2/oss"
"github.com/aliyun/alibabacloud-oss-go-sdk-v2/oss/credentials"
)
func main() {
// Specify the region where the bucket is located. For example, set the region to cn-hangzhou for China (Hangzhou).
var region = "cn-hangzhou"
// Load the default configurations and set the credential provider and region.
cfg := oss.LoadDefaultConfig().
WithCredentialsProvider(credentials.NewEnvironmentVariableCredentialsProvider()).
WithRegion(region)
// Create an OSS client.
client := oss.NewClient(cfg)
// Define the bucket name and requester ID.
bucketName := "examplebucket"
requester := "2033310434633xxxx"
// Create the input parameters for the operation, including the action, method type, and other parameters.
input := &oss.OperationInput{
OpName: "DeleteBucketRequesterQoSInfo", // The action.
Method: "DELETE", // The HTTP method.
Parameters: map[string]string{
"requesterQosInfo": "", // Requester QoS-related parameters.
"qosRequester": requester, // The requester ID.
},
Headers: map[string]string{}, // The HTTP headers.
Body: nil, // The request body. It is usually empty for a DELETE request.
Bucket: oss.Ptr(bucketName), // The bucket name.
}
// Execute the operation and receive the response or an error.
res, err := client.InvokeOperation(context.TODO(), input)
if err != nil {
// If an error occurs, print the error message and exit the program.
fmt.Printf("invoke operation got error: %v\n", err)
os.Exit(1)
}
// Print the operation result.
fmt.Println("The result of DeleteBucketRequesterQoSInfo:", res.Status)
}
Bandwidth management for different requesters at the resource pool level
Get information about all resource pools under the current account
package main
import (
"context"
"fmt"
"io"
"os"
"github.com/aliyun/alibabacloud-oss-go-sdk-v2/oss"
"github.com/aliyun/alibabacloud-oss-go-sdk-v2/oss/credentials"
)
func main() {
// Specify the region where the bucket is located. For example, set the region to cn-hangzhou for China (Hangzhou).
var region = "cn-hangzhou"
// Load the default configurations and set the credential provider and region.
cfg := oss.LoadDefaultConfig().
WithCredentialsProvider(credentials.NewEnvironmentVariableCredentialsProvider()).
WithRegion(region)
// Create an OSS client.
client := oss.NewClient(cfg)
// Create the input parameters for the operation, including the action, method type, and other parameters.
input := &oss.OperationInput{
OpName: "ListResourcePools", // The action.
Method: "GET", // The HTTP method.
Parameters: map[string]string{
"resourcePool": "", // Resource pool-related parameters.
// Optional parameters:
// "continuation-token": "example-resource-pool", // The continuation token for paging.
// "max-keys": "1", // The maximum number of entries to return.
},
Headers: map[string]string{}, // The HTTP headers.
Body: nil, // The request body. It is usually empty for a GET request.
Bucket: nil, // This operation does not apply to a specific bucket.
}
// Execute the operation and receive the response or an error.
res, err := client.InvokeOperation(context.TODO(), input)
if err != nil {
// If an error occurs, print the error message and exit the program.
fmt.Printf("invoke operation got error: %v\n", err)
os.Exit(1)
}
// Read the response body.
body, err := io.ReadAll(res.Body)
if err != nil {
// If an error occurs while reading the response body, print the error message and exit the program.
fmt.Printf("failed to read response body: %v\n", err)
os.Exit(1)
}
// Close the response body to ensure that resources are released.
if res.Body != nil {
res.Body.Close()
}
// Print the operation result.
fmt.Println("The result of ListResourcePools:", string(body))
}
Get information about a specified resource pool
package main
import (
"context"
"fmt"
"io"
"os"
"github.com/aliyun/alibabacloud-oss-go-sdk-v2/oss"
"github.com/aliyun/alibabacloud-oss-go-sdk-v2/oss/credentials"
)
func main() {
// Specify the region where the bucket is located. For example, set the region to cn-hangzhou for China (Hangzhou).
var region = "cn-hangzhou"
// Load the default configurations and set the credential provider and region.
cfg := oss.LoadDefaultConfig().
WithCredentialsProvider(credentials.NewEnvironmentVariableCredentialsProvider()).
WithRegion(region)
// Create an OSS client.
client := oss.NewClient(cfg)
// Create the input parameters for the operation, including the action, method type, and other parameters.
input := &oss.OperationInput{
OpName: "GetResourcePoolInfo", // The action.
Method: "GET", // The HTTP method.
Parameters: map[string]string{
"resourcePoolInfo": "", // Resource pool-related parameters.
"resourcePool": "example-resource-pool", // The name of the resource pool whose information you want to query.
},
Headers: map[string]string{}, // The HTTP headers.
Body: nil, // The request body. It is usually empty for a GET request.
Bucket: nil, // This operation does not apply to a specific bucket.
}
// Execute the operation and receive the response or an error.
res, err := client.InvokeOperation(context.TODO(), input)
if err != nil {
// If an error occurs, print the error message and exit the program.
fmt.Printf("invoke operation got error: %v\n", err)
os.Exit(1)
}
// Read the response body.
body, err := io.ReadAll(res.Body)
if err != nil {
// If an error occurs while reading the response body, print the error message and exit the program.
fmt.Printf("failed to read response body: %v\n", err)
os.Exit(1)
}
// Close the response body to ensure that resources are released.
if res.Body != nil {
res.Body.Close()
}
// Print the operation result.
fmt.Println("The result of GetResourcePoolInfo:", string(body))
}
Get the list of buckets in a specified resource pool
package main
import (
"context"
"fmt"
"io"
"os"
"github.com/aliyun/alibabacloud-oss-go-sdk-v2/oss"
"github.com/aliyun/alibabacloud-oss-go-sdk-v2/oss/credentials"
)
func main() {
// Specify the region where the bucket is located. For example, set the region to cn-hangzhou for China (Hangzhou).
var region = "cn-hangzhou"
// Load the default configurations and set the credential provider and region.
cfg := oss.LoadDefaultConfig().
WithCredentialsProvider(credentials.NewEnvironmentVariableCredentialsProvider()).
WithRegion(region)
// Create an OSS client.
client := oss.NewClient(cfg)
// Create the input parameters for the operation, including the action, method type, and other parameters.
input := &oss.OperationInput{
OpName: "ListResourcePoolBucketGroups", // The action.
Method: "GET", // The HTTP method.
Parameters: map[string]string{ // The parameter list.
"resourcePool": "example-resource-pool", // The resource pool name.
},
Headers: map[string]string{}, // The HTTP headers.
Body: nil, // The request body.
Bucket: nil, // The bucket name. This is left empty because the operation does not apply to a specific bucket.
}
// Execute the operation and receive the response or an error.
res, err := client.InvokeOperation(context.TODO(), input)
if err != nil {
// If an error occurs, print the error message and exit the program.
fmt.Printf("invoke operation got error: %v\n", err)
os.Exit(1)
}
// Read the response body.
body, err := io.ReadAll(res.Body)
if err != nil {
// If an error occurs while reading the response body, print the error message and exit the program.
fmt.Printf("failed to read response body: %v\n", err)
os.Exit(1)
}
// Close the response body to ensure that resources are released.
if res.Body != nil {
res.Body.Close()
}
// Print the operation result.
fmt.Println("The result of ListResourcePoolBucketGroups:", string(body))
}
Configure throttling for a requester of a resource pool
package main
import (
"bytes"
"context"
"crypto/md5"
"encoding/base64"
"fmt"
"os"
"github.com/aliyun/alibabacloud-oss-go-sdk-v2/oss"
"github.com/aliyun/alibabacloud-oss-go-sdk-v2/oss/credentials"
)
func main() {
// Specify the region where the bucket is located. For example, set the region to cn-hangzhou for China (Hangzhou).
var region = "cn-hangzhou"
// Load the default configurations and set the credential provider and region.
cfg := oss.LoadDefaultConfig().
WithCredentialsProvider(credentials.NewEnvironmentVariableCredentialsProvider()).
WithRegion(region)
// Create an OSS client.
client := oss.NewClient(cfg)
// Define the resource pool name and requester ID.
resourcePool := "example-resource-pool"
requester := "2598733333333xxxx"
// Read the content of the QoS configuration file.
qosConf, err := os.ReadFile("qos.xml")
if err != nil {
// If an error occurs while reading the QoS configuration file, print the error message and exit the program.
fmt.Printf("failed to read qos.xml: %v\n", err)
os.Exit(1)
}
// Calculate the MD5 hash of the input data and convert it to a Base64-encoded string.
calcMd5 := func(input []byte) string {
if len(input) == 0 {
return "1B2M2Y8AsgTpgAmY7PhCfg=="
}
h := md5.New()
h.Write(input)
return base64.StdEncoding.EncodeToString(h.Sum(nil))
}
// Create the input parameters for the operation, including the action, method type, and other parameters.
input := &oss.OperationInput{
OpName: "PutResourcePoolRequesterQoSInfo", // The action.
Method: "PUT", // The HTTP method.
Parameters: map[string]string{
"requesterQosInfo": "", // Requester QoS-related parameters.
"resourcePool": resourcePool, // The resource pool name.
"qosRequester": requester, // The requester ID.
},
Headers: map[string]string{
"Content-MD5": calcMd5(qosConf), // Set the MD5 hash of the request body for data integrity validation.
},
Body: bytes.NewReader(qosConf), // The request body, which contains the QoS configuration content.
Bucket: nil, // This operation does not apply to a specific bucket.
}
// Execute the operation and receive the response or an error.
res, err := client.InvokeOperation(context.TODO(), input)
if err != nil {
// If an error occurs, print the error message and exit the program.
fmt.Printf("invoke operation got error: %v\n", err)
os.Exit(1)
}
// Print the operation result.
fmt.Println("The result of PutResourcePoolRequesterQoSInfo:", res.Status)
}
Get the throttling configurations for a specified requester in a resource pool
package main
import (
"context"
"fmt"
"io"
"os"
"github.com/aliyun/alibabacloud-oss-go-sdk-v2/oss"
"github.com/aliyun/alibabacloud-oss-go-sdk-v2/oss/credentials"
)
func main() {
// Specify the region where the bucket is located. For example, set the region to cn-hangzhou for China (Hangzhou).
var region = "cn-hangzhou"
// Load the default configurations and set the credential provider and region.
cfg := oss.LoadDefaultConfig().
WithCredentialsProvider(credentials.NewEnvironmentVariableCredentialsProvider()).
WithRegion(region)
// Create an OSS client.
client := oss.NewClient(cfg)
// Define the resource pool name and requester ID.
resourcePool := "example-resource-pool"
requester := "2598732222222xxxx"
// Create the input parameters for the operation, including the action, method type, and other parameters.
input := &oss.OperationInput{
OpName: "GetResourcePoolRequesterQoSInfo", // The action.
Method: "GET", // The HTTP method.
Parameters: map[string]string{
"requesterQosInfo": "", // Requester QoS-related parameters.
"resourcePool": resourcePool, // The resource pool name.
"qosRequester": requester, // The requester ID.
},
Headers: map[string]string{}, // The HTTP headers.
Body: nil, // A request body is usually not required for a GET request.
Bucket: nil, // This operation does not apply to a specific bucket.
}
// Execute the operation and receive the response or an error.
res, err := client.InvokeOperation(context.TODO(), input)
if err != nil {
// If an error occurs, print the error message and exit the program.
fmt.Printf("invoke operation got error: %v\n", err)
os.Exit(1)
}
// Read the response body.
body, err := io.ReadAll(res.Body)
if err != nil {
// If an error occurs while reading the response body, print the error message and exit the program.
fmt.Printf("failed to read response body: %v\n", err)
os.Exit(1)
}
// Close the response body to ensure that resources are released.
if res.Body != nil {
res.Body.Close()
}
// Print the operation result.
fmt.Println("The result of GetResourcePoolRequesterQoSInfo:", string(body))
}
Get the throttling configurations for all requesters in a resource pool
package main
import (
"context"
"fmt"
"io"
"os"
"github.com/aliyun/alibabacloud-oss-go-sdk-v2/oss"
"github.com/aliyun/alibabacloud-oss-go-sdk-v2/oss/credentials"
)
func main() {
// Specify the region where the bucket is located. For example, set the region to cn-hangzhou for China (Hangzhou).
var region = "cn-hangzhou"
// Load the default configurations and set the credential provider and region.
cfg := oss.LoadDefaultConfig().
WithCredentialsProvider(credentials.NewEnvironmentVariableCredentialsProvider()).
WithRegion(region)
// Create an OSS client.
client := oss.NewClient(cfg)
// Define the resource pool name.
resourcePool := "example-resource-pool"
// Create the input parameters for the operation, including the action, method type, and other parameters.
input := &oss.OperationInput{
OpName: "ListResourcePoolRequesterQoSInfos", // The action.
Method: "GET", // The HTTP method.
Parameters: map[string]string{
"requesterQosInfo": "", // Requester QoS-related parameters.
"resourcePool": resourcePool, // The resource pool name.
// Optional parameters:
// "continuation-token": "25987311111111xxxx", // The continuation token for paging.
// "max-keys": "1", // The maximum number of entries to return.
},
Headers: map[string]string{}, // The HTTP headers.
Body: nil, // A request body is usually not required for a GET request.
Bucket: nil, // This operation does not apply to a specific bucket.
}
// Execute the operation and receive the response or an error.
res, err := client.InvokeOperation(context.TODO(), input)
if err != nil {
// If an error occurs, print the error message and exit the program.
fmt.Printf("invoke operation got error: %v\n", err)
os.Exit(1)
}
// Read the response body.
body, err := io.ReadAll(res.Body)
if err != nil {
// If an error occurs while reading the response body, print the error message and exit the program.
fmt.Printf("failed to read response body: %v\n", err)
os.Exit(1)
}
// Close the response body to ensure that resources are released.
if res.Body != nil {
res.Body.Close()
}
// Print the operation result.
fmt.Println("The result of ListResourcePoolRequesterQoSInfos:", string(body))
}
Delete the throttling configurations for a specified requester in a resource pool
package main
import (
"context"
"fmt"
"os"
"github.com/aliyun/alibabacloud-oss-go-sdk-v2/oss"
"github.com/aliyun/alibabacloud-oss-go-sdk-v2/oss/credentials"
)
func main() {
// Specify the region where the bucket is located. For example, set the region to cn-hangzhou for China (Hangzhou).
var region = "cn-hangzhou"
// Load the default configurations and set the credential provider and region.
cfg := oss.LoadDefaultConfig().
WithCredentialsProvider(credentials.NewEnvironmentVariableCredentialsProvider()).
WithRegion(region)
// Create an OSS client.
client := oss.NewClient(cfg)
// Define the resource pool name and requester ID.
resourcePool := "example-resource-pool"
requester := "2598732222222xxxx"
// Create the input parameters for the operation, including the action, method type, and other parameters.
input := &oss.OperationInput{
OpName: "DeleteResourcePoolRequesterQoSInfo", // The action.
Method: "DELETE", // The HTTP method.
Parameters: map[string]string{
"requesterQosInfo": "", // Requester QoS-related parameters.
"resourcePool": resourcePool, // The resource pool name.
"qosRequester": requester, // The requester ID.
},
Headers: map[string]string{}, // The HTTP headers.
Body: nil, // A request body is usually not required for a DELETE request.
Bucket: nil, // This operation does not apply to a specific bucket.
}
// Execute the operation and receive the response or an error.
res, err := client.InvokeOperation(context.TODO(), input)
if err != nil {
// If an error occurs, print the error message and exit the program.
fmt.Printf("invoke operation got error: %v\n", err)
os.Exit(1)
}
// Print the operation result.
fmt.Println("The result of DeleteResourcePoolRequesterQoSInfo:", res.Status)
}
Resource pool priority QoS management
Set the priority QoS configurations for a resource pool
package main
import (
"bytes"
"context"
"crypto/md5"
"encoding/base64"
"fmt"
"os"
"github.com/aliyun/alibabacloud-oss-go-sdk-v2/oss"
"github.com/aliyun/alibabacloud-oss-go-sdk-v2/oss/credentials"
)
func main() {
// Specify the region where the bucket is located. For example, set the region to cn-hangzhou for China (Hangzhou).
var region = "cn-hangzhou"
// Load the default configurations and set the credential provider and region.
cfg := oss.LoadDefaultConfig().
WithCredentialsProvider(credentials.NewEnvironmentVariableCredentialsProvider()).
WithRegion(region)
// Create an OSS client.
client := oss.NewClient(cfg)
// Define the resource pool name.
resourcePool := "hz-rp-01"
// Read the content of the priority QoS configuration file.
qosConf, err := os.ReadFile("priority-qos.xml")
if err != nil {
// If an error occurs while reading the QoS configuration file, print the error message and exit the program.
fmt.Printf("failed to read qos.xml: %v\n", err)
os.Exit(1)
}
// Calculate the MD5 hash of the input data and convert it to a Base64-encoded string.
calcMd5 := func(input []byte) string {
if len(input) == 0 {
return "1B2M2Y8AsgTpgAmY7PhCfg=="
}
h := md5.New()
h.Write(input)
return base64.StdEncoding.EncodeToString(h.Sum(nil))
}
// Create the input parameters for the operation, including the action, method type, and other parameters.
input := &oss.OperationInput{
OpName: "PutResourcePoolPriorityQoSConfiguration", // The action.
Method: "PUT", // The HTTP method.
Parameters: map[string]string{
"priorityQos": "", // Priority QoS-related parameters.
"resourcePool": resourcePool, // The resource pool name.
},
Headers: map[string]string{
"Content-MD5": calcMd5(qosConf), // Set the MD5 hash of the request body for data integrity validation.
},
Body: bytes.NewReader(qosConf), // The request body, which contains the QoS configuration content.
Bucket: nil, // This operation does not apply to a specific bucket.
}
// Execute the operation and receive the response or an error.
res, err := client.InvokeOperation(context.TODO(), input)
if err != nil {
// If an error occurs, print the error message and exit the program.
fmt.Printf("invoke operation got error: %v\n", err)
os.Exit(1)
}
// Print the operation result.
fmt.Println("The result of PutResourcePoolPriorityQoSConfiguration:", res.Status)
}
Get the priority QoS configurations of a resource pool
package main
import (
"context"
"fmt"
"io"
"os"
"github.com/aliyun/alibabacloud-oss-go-sdk-v2/oss"
"github.com/aliyun/alibabacloud-oss-go-sdk-v2/oss/credentials"
)
func main() {
// Specify the region where the bucket is located. For example, set the region to cn-hangzhou for China (Hangzhou).
var region = "cn-hangzhou"
// Load the default configurations and set the credential provider and region.
cfg := oss.LoadDefaultConfig().
WithCredentialsProvider(credentials.NewEnvironmentVariableCredentialsProvider()).
WithRegion(region)
// Create an OSS client.
client := oss.NewClient(cfg)
// Define the resource pool name.
resourcePool := "hz-rp-01"
// Create the input parameters for the operation, including the action, method type, and other parameters.
input := &oss.OperationInput{
OpName: "GetResourcePoolPriorityQoSConfiguration", // The action.
Method: "GET", // The HTTP method.
Parameters: map[string]string{
"priorityQos": "", // Priority QoS-related parameters.
"resourcePool": resourcePool, // The resource pool name.
},
Headers: map[string]string{}, // The HTTP headers.
Body: nil, // A request body is usually not required for a GET request.
Bucket: nil, // This operation does not apply to a specific bucket.
}
// Execute the operation and receive the response or an error.
res, err := client.InvokeOperation(context.TODO(), input)
if err != nil {
// If an error occurs, print the error message and exit the program.
fmt.Printf("invoke operation got error: %v\n", err)
os.Exit(1)
}
// Read the response body.
body, err := io.ReadAll(res.Body)
if err != nil {
// If an error occurs while reading the response body, print the error message and exit the program.
fmt.Printf("failed to read response body: %v\n", err)
os.Exit(1)
}
// Close the response body to ensure that resources are released.
if res.Body != nil {
res.Body.Close()
}
// Print the operation result.
fmt.Println("The result of GetResourcePoolPriorityQosConfiguration:", string(body))
}
Delete the priority QoS configurations of a resource pool
package main
import (
"bytes"
"context"
"crypto/md5"
"encoding/base64"
"fmt"
"os"
"github.com/aliyun/alibabacloud-oss-go-sdk-v2/oss"
"github.com/aliyun/alibabacloud-oss-go-sdk-v2/oss/credentials"
)
func main() {
// Specify the region where the bucket is located. For example, set the region to cn-hangzhou for China (Hangzhou).
var region = "cn-hangzhou"
// Load the default configurations and set the credential provider and region.
cfg := oss.LoadDefaultConfig().
WithCredentialsProvider(credentials.NewEnvironmentVariableCredentialsProvider()).
WithRegion(region)
// Create an OSS client.
client := oss.NewClient(cfg)
// Define the resource pool name.
resourcePool := "hz-rp-01"
// Read the content of the priority QoS configuration file.
qosConf, err := os.ReadFile("priority-qos.xml")
if err != nil {
// If an error occurs while reading the QoS configuration file, print the error message and exit the program.
fmt.Printf("failed to read qos.xml: %v\n", err)
os.Exit(1)
}
// Calculate the MD5 hash of the input data and convert it to a Base64-encoded string.
calcMd5 := func(input []byte) string {
if len(input) == 0 {
return "1B2M2Y8AsgTpgAmY7PhCfg=="
}
h := md5.New()
h.Write(input)
return base64.StdEncoding.EncodeToString(h.Sum(nil))
}
// Create the input parameters for the operation, including the action, method type, and other parameters.
input := &oss.OperationInput{
OpName: "DeleteResourcePoolPriorityQosConfiguration", // The action.
Method: "DELETE", // The HTTP method.
Parameters: map[string]string{
"priorityQos": "", // Priority QoS-related parameters.
"resourcePool": resourcePool, // The resource pool name.
},
Headers: map[string]string{
"Content-MD5": calcMd5(qosConf), // Set the MD5 hash of the request body for data integrity validation.
},
Body: bytes.NewReader(qosConf), // The request body, which contains the QoS configuration content.
Bucket: nil, // This operation does not apply to a specific bucket.
}
// Execute the operation and receive the response or an error.
res, err := client.InvokeOperation(context.TODO(), input)
if err != nil {
// If an error occurs, print the error message and exit the program.
fmt.Printf("invoke operation got error: %v\n", err)
os.Exit(1)
}
// Print the operation result.
fmt.Println("The result of DeleteResourcePoolPriorityQosConfiguration:", res.Status)
}
Set the priority QoS configurations for a requester in a resource pool
package main
import (
"bytes"
"context"
"crypto/md5"
"encoding/base64"
"fmt"
"os"
"github.com/aliyun/alibabacloud-oss-go-sdk-v2/oss"
"github.com/aliyun/alibabacloud-oss-go-sdk-v2/oss/credentials"
)
func main() {
// Specify the region where the bucket is located. For example, set the region to cn-hangzhou for China (Hangzhou).
var region = "cn-hangzhou"
// Load the default configurations and set the credential provider and region.
cfg := oss.LoadDefaultConfig().
WithCredentialsProvider(credentials.NewEnvironmentVariableCredentialsProvider()).
WithRegion(region)
// Create an OSS client.
client := oss.NewClient(cfg)
// Define the resource pool name.
resourcePool := "hz-rp-01"
// Read the content of the requester priority QoS configuration file.
qosConf, err := os.ReadFile("requester-priority-qos.xml")
if err != nil {
// If an error occurs while reading the QoS configuration file, print the error message and exit the program.
fmt.Printf("failed to read qos.xml: %v\n", err)
os.Exit(1)
}
// Calculate the MD5 hash of the input data and convert it to a Base64-encoded string.
calcMd5 := func(input []byte) string {
if len(input) == 0 {
return "1B2M2Y8AsgTpgAmY7PhCfg=="
}
h := md5.New()
h.Write(input)
return base64.StdEncoding.EncodeToString(h.Sum(nil))
}
// Create the input parameters for the operation, including the action, method type, and other parameters.
input := &oss.OperationInput{
OpName: "PutResourcePoolRequesterPriorityQoSConfiguration", // The action.
Method: "PUT", // The HTTP method.
Parameters: map[string]string{
"requesterPriorityQos": "", // Requester priority QoS-related parameters.
"resourcePool": resourcePool, // The resource pool name.
},
Headers: map[string]string{
"Content-MD5": calcMd5(qosConf), // Set the MD5 hash of the request body for data integrity validation.
},
Body: bytes.NewReader(qosConf), // The request body, which contains the QoS configuration content.
Bucket: nil, // This operation does not apply to a specific bucket.
}
// Execute the operation and receive the response or an error.
res, err := client.InvokeOperation(context.TODO(), input)
if err != nil {
// If an error occurs, print the error message and exit the program.
fmt.Printf("invoke operation got error: %v\n", err)
os.Exit(1)
}
// Print the operation result.
fmt.Println("The result of PutResourcePoolRequesterPriorityQoSConfiguration:", res.Status)
}
Get the priority QoS configurations for a requester in a resource pool
package main
import (
"context"
"fmt"
"io"
"os"
"github.com/aliyun/alibabacloud-oss-go-sdk-v2/oss"
"github.com/aliyun/alibabacloud-oss-go-sdk-v2/oss/credentials"
)
func main() {
// Specify the region where the bucket is located. For example, set the region to cn-hangzhou for China (Hangzhou).
var region = "cn-hangzhou"
// Load the default configurations and set the credential provider and region.
cfg := oss.LoadDefaultConfig().
WithCredentialsProvider(credentials.NewEnvironmentVariableCredentialsProvider()).
WithRegion(region)
// Create an OSS client.
client := oss.NewClient(cfg)
// Define the resource pool name.
resourcePool := "hz-rp-01"
// Create the input parameters for the operation, including the action, method type, and other parameters.
input := &oss.OperationInput{
OpName: "GetResourcePoolRequesterPriorityQoSConfiguration", // The action.
Method: "GET", // The HTTP method.
Parameters: map[string]string{
"requesterPriorityQos": "", // Requester priority QoS-related parameters.
"resourcePool": resourcePool, // The resource pool name.
},
Headers: map[string]string{}, // The HTTP headers.
Body: nil, // A request body is usually not required for a GET request.
Bucket: nil, // This operation does not apply to a specific bucket.
}
// Execute the operation and receive the response or an error.
res, err := client.InvokeOperation(context.TODO(), input)
if err != nil {
// If an error occurs, print the error message and exit the program.
fmt.Printf("invoke operation got error: %v\n", err)
os.Exit(1)
}
// Read the response body.
body, err := io.ReadAll(res.Body)
if err != nil {
// If an error occurs while reading the response body, print the error message and exit the program.
fmt.Printf("failed to read response body: %v\n", err)
os.Exit(1)
}
// Close the response body to ensure that resources are released.
if res.Body != nil {
res.Body.Close()
}
// Print the operation result.
fmt.Println("The result of GetResourcePoolRequesterPriorityQosConfiguration:", string(body))
}
Delete the priority QoS configurations for a requester in a resource pool
package main
import (
"bytes"
"context"
"crypto/md5"
"encoding/base64"
"fmt"
"os"
"github.com/aliyun/alibabacloud-oss-go-sdk-v2/oss"
"github.com/aliyun/alibabacloud-oss-go-sdk-v2/oss/credentials"
)
func main() {
// Specify the region where the bucket is located. For example, set the region to cn-hangzhou for China (Hangzhou).
var region = "cn-hangzhou"
// Load the default configurations and set the credential provider and region.
cfg := oss.LoadDefaultConfig().
WithCredentialsProvider(credentials.NewEnvironmentVariableCredentialsProvider()).
WithRegion(region)
// Create an OSS client.
client := oss.NewClient(cfg)
// Define the resource pool name.
resourcePool := "hz-rp-01"
// Read the content of the requester priority QoS configuration file.
qosConf, err := os.ReadFile("priority-qos.xml")
if err != nil {
// If an error occurs while reading the QoS configuration file, print the error message and exit the program.
fmt.Printf("failed to read qos.xml: %v\n", err)
os.Exit(1)
}
// Calculate the MD5 hash of the input data and convert it to a Base64-encoded string.
calcMd5 := func(input []byte) string {
if len(input) == 0 {
return "1B2M2Y8AsgTpgAmY7PhCfg=="
}
h := md5.New()
h.Write(input)
return base64.StdEncoding.EncodeToString(h.Sum(nil))
}
// Create the input parameters for the operation, including the action, method type, and other parameters.
input := &oss.OperationInput{
OpName: "DeleteResourcePoolRequesterPriorityQoSConfiguration", // The action.
Method: "DELETE", // The HTTP method.
Parameters: map[string]string{
"requesterPriorityQos": "", // Requester priority QoS-related parameters.
"resourcePool": resourcePool, // The resource pool name.
},
Headers: map[string]string{
"Content-MD5": calcMd5(qosConf), // Set the MD5 hash of the request body for data integrity validation.
},
Body: bytes.NewReader(qosConf), // The request body, which contains the QoS configuration content.
Bucket: nil, // This operation does not apply to a specific bucket.
}
// Execute the operation and receive the response or an error.
res, err := client.InvokeOperation(context.TODO(), input)
if err != nil {
// If an error occurs, print the error message and exit the program.
fmt.Printf("invoke operation got error: %v\n", err)
os.Exit(1)
}
// Print the operation result.
fmt.Println("The result of DeleteResourcePoolRequesterPriorityQosConfiguration:", res.Status)
}
Bucket group bandwidth management
Add a bucket from a resource pool to a specified bucket group
package main
import (
"context"
"fmt"
"io"
"os"
"strings"
"github.com/aliyun/alibabacloud-oss-go-sdk-v2/oss"
"github.com/aliyun/alibabacloud-oss-go-sdk-v2/oss/credentials"
)
// The PutBucketResourcePoolBucketGroup function adds a bucket in a resource pool to a specified bucket group.
func main() {
// Specify the region where the bucket is located. For example, set the region to cn-hangzhou for China (Hangzhou).
var region = "cn-hangzhou"
// Load the default configurations and set the credential provider and region.
cfg := oss.LoadDefaultConfig().
WithCredentialsProvider(credentials.NewEnvironmentVariableCredentialsProvider()).
WithRegion(region)
// Create an OSS client.
client := oss.NewClient(cfg)
// Create the input parameters for the operation, including the action, method type, and other parameters.
input := &oss.OperationInput{
OpName: "PutBucketResourcePoolBucketGroup", // The action.
Method: "PUT", // The HTTP method.
Parameters: map[string]string{ // The parameter list.
"resourcePoolBucketGroup": "example-group", // The name of the bucket group in the resource pool.
"resourcePool": "example-resource-pool", // The resource pool name.
},
Headers: map[string]string{}, // The HTTP headers.
Body: nil, // The request body.
Bucket: oss.Ptr("test-bucket"), // The bucket name.
}
// Execute the operation and receive the response or an error.
res, err := client.InvokeOperation(context.TODO(), input)
if err != nil {
// If an error occurs, print the error message and exit the program.
fmt.Printf("invoke operation got error: %v\n", err)
os.Exit(1)
}
var body []byte
if b, ok := res.Body.(io.Reader); ok {
buf := new(strings.Builder)
_, _ = io.Copy(buf, b)
body = []byte(buf.String())
} else {
body = []byte(fmt.Sprintf("%v", res.Body))
}
// Print the operation result.
fmt.Println("The result of PutBucketResourcePoolBucketGroup:", string(body))
}
Get the list of bucket groups in a specified resource pool
package main
import (
"context"
"fmt"
"io"
"os"
"github.com/aliyun/alibabacloud-oss-go-sdk-v2/oss"
"github.com/aliyun/alibabacloud-oss-go-sdk-v2/oss/credentials"
)
// The ListResourcePoolBucketGroups function lists the bucket groups in a specified resource pool.
func main() {
// Define the region. For example, use "cn-hangzhou".
var region = "cn-hangzhou"
// Load the default configurations and set the credential provider and region.
cfg := oss.LoadDefaultConfig().
WithCredentialsProvider(credentials.NewEnvironmentVariableCredentialsProvider()).
WithRegion(region)
// Create an OSS client.
client := oss.NewClient(cfg)
// Create the input parameters for the operation, including the action, method type, and other parameters.
input := &oss.OperationInput{
OpName: "ListResourcePoolBucketGroups", // The action.
Method: "GET", // The HTTP method.
Parameters: map[string]string{ // The parameter list.
"resourcePool": "example-resource-pool", // The resource pool name.
},
Headers: map[string]string{}, // The HTTP headers.
Body: nil, // The request body.
Bucket: nil, // The bucket name. This is left empty because the operation does not apply to a specific bucket.
}
// Execute the operation and receive the response or an error.
res, err := client.InvokeOperation(context.TODO(), input)
if err != nil {
// If an error occurs, print the error message and exit the program.
fmt.Printf("invoke operation got error: %v\n", err)
os.Exit(1)
}
// Read the response body.
body, err := io.ReadAll(res.Body)
if err != nil {
// If an error occurs while reading the response body, print the error message and exit the program.
fmt.Printf("failed to read response body: %v\n", err)
os.Exit(1)
}
// Close the response body to ensure that resources are released.
if res.Body != nil {
res.Body.Close()
}
// Print the operation result.
fmt.Println("The result of ListResourcePoolBucketGroups:", string(body))
}
Modify the throttling configurations of a bucket group in a resource pool
package main
import (
"bytes"
"context"
"crypto/md5"
"encoding/base64"
"fmt"
"os"
"github.com/aliyun/alibabacloud-oss-go-sdk-v2/oss"
"github.com/aliyun/alibabacloud-oss-go-sdk-v2/oss/credentials"
)
func main() {
// Specify the region where the bucket is located. For example, set the region to cn-hangzhou for China (Hangzhou).
var region = "cn-hangzhou"
// Load the default configurations and set the credential provider and region.
cfg := oss.LoadDefaultConfig().
WithCredentialsProvider(credentials.NewEnvironmentVariableCredentialsProvider()).
WithRegion(region)
// Create an OSS client.
client := oss.NewClient(cfg)
// Define the resource pool name and bucket group name.
resourcePool := "example-resource-pool"
group := "example-group"
// Read the content of the QoS configuration file.
qosConf, err := os.ReadFile("qos.xml")
if err != nil {
// If an error occurs while reading the QoS configuration file, print the error message and exit the program.
fmt.Printf("failed to read qos.xml: %v\n", err)
os.Exit(1)
}
// Calculate the MD5 hash of the input data and convert it to a Base64-encoded string.
calcMd5 := func(input []byte) string {
if len(input) == 0 {
return "1B2M2Y8AsgTpgAmY7PhCfg=="
}
h := md5.New()
h.Write(input)
return base64.StdEncoding.EncodeToString(h.Sum(nil))
}
// Create the input parameters for the operation, including the action, method type, and other parameters.
input := &oss.OperationInput{
OpName: "PutResourcePoolBucketGroupQoSInfo", // The action.
Method: "PUT", // The HTTP method.
Parameters: map[string]string{ // The parameter list.
"resourcePool": resourcePool, // The resource pool name.
"resourcePoolBucketGroup": group, // The bucket group name.
"resourcePoolBucketGroupQosInfo": "", // QoS-related parameters.
},
Headers: map[string]string{ // The HTTP headers.
"Content-MD5": calcMd5(qosConf), // Set the MD5 hash of the request body for data integrity validation.
},
Body: bytes.NewReader(qosConf), // The request body, which contains the QoS configuration content.
Bucket: nil, // The bucket name. This is left empty because the operation does not apply to a specific bucket.
}
// Execute the operation and receive the response or an error.
res, err := client.InvokeOperation(context.TODO(), input)
if err != nil {
// If an error occurs, print the error message and exit the program.
fmt.Printf("invoke operation got error: %v\n", err)
os.Exit(1)
}
// Print the operation result.
fmt.Println("The result of PutResourcePoolBucketGroupQoSInfo:", res.Status)
}
Get the throttling configurations of a bucket group in a resource pool
package main
import (
"context"
"fmt"
"io"
"os"
"github.com/aliyun/alibabacloud-oss-go-sdk-v2/oss"
"github.com/aliyun/alibabacloud-oss-go-sdk-v2/oss/credentials"
)
// The GetResourcePoolBucketGroupQosInfo function gets the QoS information of a specified bucket group in a resource pool.
func main() {
// Specify the region where the bucket is located. For example, set the region to cn-hangzhou for China (Hangzhou).
var region = "cn-hangzhou"
// Load the default configurations and set the credential provider and region.
cfg := oss.LoadDefaultConfig().
WithCredentialsProvider(credentials.NewEnvironmentVariableCredentialsProvider()).
WithRegion(region)
// Create an OSS client.
client := oss.NewClient(cfg)
// Define the resource pool name and bucket group name.
resourcePool := "example-resource-pool"
ResourcePoolBucketGroup := "example-group"
// Create the input parameters for the operation, including the action, method type, and other parameters.
input := &oss.OperationInput{
OpName: "GetResourcePoolBucketGroupQoSInfo", // The action.
Method: "GET", // The HTTP method.
Parameters: map[string]string{ // The parameter list.
"resourcePool": resourcePool, // The resource pool name.
"resourcePoolBucketGroup": ResourcePoolBucketGroup, // The bucket group name.
"resourcePoolBucketGroupQoSInfo": "", // QoS-related parameters.
},
Headers: map[string]string{}, // The HTTP headers.
Body: nil, // The request body. It is usually empty for a GET request.
Bucket: nil, // The bucket name. This is left empty because the operation does not apply to a specific bucket.
}
// Execute the operation and receive the response or an error.
res, err := client.InvokeOperation(context.TODO(), input)
if err != nil {
// If an error occurs, print the error message and exit the program.
fmt.Printf("invoke operation got error: %v\n", err)
os.Exit(1)
}
// Read the response body.
body, err := io.ReadAll(res.Body)
if err != nil {
// If an error occurs while reading the response body, print the error message and exit the program.
fmt.Printf("failed to read response body: %v\n", err)
os.Exit(1)
}
// Close the response body to ensure that resources are released.
if res.Body != nil {
res.Body.Close()
}
// Print the operation result.
fmt.Println("The result of GetResourcePoolBucketGroupQoSInfo:", string(body))
}
List the throttling configurations of bucket groups in a resource pool
package main
import (
"context"
"fmt"
"io"
"os"
"github.com/aliyun/alibabacloud-oss-go-sdk-v2/oss"
"github.com/aliyun/alibabacloud-oss-go-sdk-v2/oss/credentials"
)
// The ListResourcePoolBucketGroupQosInfos function lists the QoS information of all bucket groups in a specified resource pool.
func main() {
// Specify the region where the bucket is located. For example, set the region to cn-hangzhou for China (Hangzhou).
var region = "cn-hangzhou"
// Load the default configurations and set the credential provider and region.
cfg := oss.LoadDefaultConfig().
WithCredentialsProvider(credentials.NewEnvironmentVariableCredentialsProvider()).
WithRegion(region)
// Create an OSS client.
client := oss.NewClient(cfg)
// Define the resource pool name.
resourcePool := "example-resource-pool"
// Create the input parameters for the operation, including the action, method type, and other parameters.
input := &oss.OperationInput{
OpName: "ListResourcePoolBucketGroupQoSInfos", // The action.
Method: "GET", // The HTTP method.
Parameters: map[string]string{ // The parameter list.
"resourcePool": resourcePool, // The resource pool name.
// Optional parameters:
// "continuation-token": "25987311111111xxxx", // The continuation token for paging.
// "max-keys": "1", // The maximum number of entries to return.
},
Headers: map[string]string{}, // The HTTP headers.
Body: nil, // The request body. It is usually empty for a GET request.
Bucket: nil, // The bucket name. This is left empty because the operation does not apply to a specific bucket.
}
// Execute the operation and receive the response or an error.
res, err := client.InvokeOperation(context.TODO(), input)
if err != nil {
// If an error occurs, print the error message and exit the program.
fmt.Printf("invoke operation got error: %v\n", err)
os.Exit(1)
}
// Read the response body.
body, err := io.ReadAll(res.Body)
if err != nil {
// If an error occurs while reading the response body, print the error message and exit the program.
fmt.Printf("failed to read response body: %v\n", err)
os.Exit(1)
}
// Close the response body to ensure that resources are released.
if res.Body != nil {
res.Body.Close()
}
// Print the operation result.
fmt.Println("The result of ListResourcePoolBucketGroupQoSInfos:", string(body))
}
Delete the throttling configurations of a bucket group in a resource pool
package main
import (
"context"
"fmt"
"os"
"github.com/aliyun/alibabacloud-oss-go-sdk-v2/oss"
"github.com/aliyun/alibabacloud-oss-go-sdk-v2/oss/credentials"
)
// The DeleteResourcePoolBucketGroupQosInfo function deletes the QoS information of a specified bucket group in a resource pool.
func main() {
// Define the region. For example, use "cn-hangzhou".
var region = "cn-hangzhou"
// Load the default configurations and set the credential provider and region.
cfg := oss.LoadDefaultConfig().
WithCredentialsProvider(credentials.NewEnvironmentVariableCredentialsProvider()).
WithRegion(region)
// Create an OSS client.
client := oss.NewClient(cfg)
// Define the resource pool name and bucket group name.
resourcePool := "example-resource-pool"
group := "example-group"
// Create the input parameters for the operation, including the action, method type, and other parameters.
input := &oss.OperationInput{
OpName: "DeleteResourcePoolBucketGroupQoSInfo", // The action.
Method: "DELETE", // The HTTP method.
Parameters: map[string]string{ // The parameter list.
"resourcePool": resourcePool, // The resource pool name.
"resourcePoolBucketGroup": group, // The bucket group name.
"resourcePoolBucketGroupQoSInfo": "", // QoS-related parameters.
},
Headers: map[string]string{}, // The HTTP headers.
Body: nil, // The request body. It is usually empty for a DELETE request.
Bucket: nil, // The bucket name. This is left empty because the operation does not apply to a specific bucket.
}
// Execute the operation and receive the response or an error.
res, err := client.InvokeOperation(context.TODO(), input)
if err != nil {
// If an error occurs, print the error message and exit the program.
fmt.Printf("invoke operation got error: %v\n", err)
os.Exit(1)
}
// Print the operation result.
fmt.Println("The result of DeleteResourcePoolBucketGroupQoSInfo:", res.Status)
}
References
-
For more information about resource pool QoS operations, see Resource pool QoS operations.
-
For more examples of resource pool QoS configurations, see Resource pool QoS configuration examples.
Is this page helpful?