Este tópico descreve como usar o Go SDK V2 para gerenciar e configurar a Qualidade de Serviço (QoS) de pools de recursos.
Observações
O código de exemplo deste tópico usa a região China (Hangzhou), cujo ID é
cn-hangzhou. Por padrão, utiliza-se um endpoint público. Para acessar o OSS a partir de outros produtos da Alibaba Cloud na mesma região, use um endpoint de rede privada. Para obter mais informações sobre os mapeamentos entre regiões e endpoints do OSS, consulte Regiões e Endpoints.
Gerenciamento de largura de banda do bucket
Definir limitação para buckets em um 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)
}
Obter configurações de limitação do 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))
}
Excluir as configurações de limitação de um bucket específico em um 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)
}
Gerenciamento de largura de banda para diferentes solicitantes no nível do bucket
Definir limitação para um solicitante no nível do 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)
}
Obter as configurações de limitação para um solicitante específico no nível do 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))
}
Obter as configurações de limitação para todos os solicitantes no nível do 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))
}
Excluir as configurações de limitação para um solicitante de um 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)
}
Gerenciamento de largura de banda para diferentes solicitantes no nível do pool de recursos
Obter informações sobre todos os pools de recursos da conta atual
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))
}
Obter informações sobre um 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))
}
Obter a lista de buckets em um 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 limitação para um solicitante de um 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)
}
Obter as configurações de limitação para um solicitante específico em um 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))
}
Obter as configurações de limitação para todos os solicitantes em um 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))
}
Excluir as configurações de limitação para um solicitante específico em um 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)
}
Gerenciamento de QoS de prioridade do pool de recursos
Definir as configurações de QoS de prioridade para um 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)
}
Obter as configurações de QoS de prioridade de um 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))
}
Excluir as configurações de QoS de prioridade de um 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)
}
Definir as configurações de QoS de prioridade para um solicitante em um 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)
}
Obter as configurações de QoS de prioridade para um solicitante em um 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))
}
Excluir as configurações de QoS de prioridade para um solicitante em um 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)
}
Gerenciamento de largura de banda do grupo de buckets
Adicionar um bucket de um pool de recursos a um 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))
}
Obter a lista de grupos de buckets em um 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"
)
// 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 as configurações de limitação de um grupo de buckets em um 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 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)
}
Obter as configurações de limitação de um grupo de buckets em um 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"
)
// 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 as configurações de limitação dos grupos de buckets em um 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"
)
// 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))
}
Excluir as configurações de limitação de um grupo de buckets em um 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"
)
// 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)
}
Referências
Para obter mais informações sobre operações de QoS de pool de recursos, consulte Operações de QoS de pool de recursos.
Para ver mais exemplos de configurações de QoS de pool de recursos, consulte Exemplos de configuração de QoS de pool de recursos.