Este tema describe cómo usar Go SDK V2 para gestionar y configurar la calidad de servicio (QoS) del pool de recursos.
Notas
El código de ejemplo de este tema usa la región China (Hangzhou), por ejemplo. El identificador de la región es
cn-hangzhou. De forma predeterminada, se utiliza un endpoint público. Si desea acceder a OSS desde otros productos de Alibaba Cloud en la misma región que OSS, use un endpoint de red privada. Para obtener más información sobre las asignaciones entre regiones y endpoints de OSS, consulte Regions and Endpoints.
Gestión del ancho de banda del bucket
Establecer la limitación de velocidad para los buckets de un pool de recursos
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)
}
Obtener las configuraciones de limitación de velocidad del bucket
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))
}
Eliminar las configuraciones de limitación de velocidad de un bucket específico en un pool de recursos
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)
}
Gestión del ancho de banda para distintos solicitantes a nivel de bucket
Establecer la limitación de velocidad para un solicitante a nivel de bucket
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)
}
Obtener las configuraciones de limitación de velocidad de un solicitante específico a nivel de bucket
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))
}
Obtener las configuraciones de limitación de velocidad de todos los solicitantes a nivel de bucket
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))
}
Eliminar las configuraciones de limitación de velocidad de un solicitante de un 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)
}
Gestión del ancho de banda para distintos solicitantes a nivel de pool de recursos
Obtener información de todos los pools de recursos de la cuenta actual
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))
}
Obtener información de un pool de recursos específico
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))
}
Obtener la lista de buckets de un pool de recursos específico
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))
}
Configurar la limitación de velocidad para un solicitante de un pool de recursos
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)
}
Obtener las configuraciones de limitación de velocidad de un solicitante específico en un pool de recursos
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))
}
Obtener las configuraciones de limitación de velocidad de todos los solicitantes en un pool de recursos
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))
}
Eliminar las configuraciones de limitación de velocidad de un solicitante específico en un pool de recursos
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)
}
Gestión de QoS por prioridad del pool de recursos
Establecer las configuraciones de QoS por prioridad de un pool de recursos
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)
}
Obtener las configuraciones de QoS por prioridad de un pool de recursos
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))
}
Eliminar las configuraciones de QoS por prioridad de un pool de recursos
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)
}
Establecer las configuraciones de QoS por prioridad para un solicitante en un pool de recursos
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)
}
Obtener las configuraciones de QoS por prioridad de un solicitante en un pool de recursos
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))
}
Eliminar las configuraciones de QoS por prioridad de un solicitante en un pool de recursos
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)
}
Gestión del ancho de banda de grupos de buckets
Agregar un bucket de un resource pool a un grupo de buckets específico
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))
}
Obtener la lista de grupos de buckets en un resource pool específico
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))
}
Modificar la configuración de limitación de velocidad de un grupo de buckets en un 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)
}
Obtener la configuración de limitación de velocidad de un grupo de buckets en un 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))
}
Listar las configuraciones de limitación de velocidad de los grupos de buckets en un 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))
}
Eliminar la configuración de limitación de velocidad de un grupo de buckets en un 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)
}
Referencias
Para obtener más información sobre las operaciones de QoS de resource pools, consulte Resource pool QoS operations.
Si necesita más ejemplos de configuraciones de QoS para resource pools, consulte Resource pool QoS configuration examples.