Bu konuda, bir paketin depolama kapasitesinin ve paketteki her depolama sınıfı için nesne sayısının ve depolama kapasitesinin nasıl alınacağı açıklanmaktadır.
Notlar
Bu konuda Çin (Hangzhou) bölgesinin genel uç noktası kullanılmaktadır. OSS ile aynı bölgedeki diğer Alibaba Cloud hizmetlerinden OSS'e erişmek için dahili bir uç nokta kullanın. OSS bölgeleri ve uç noktaları hakkında daha fazla bilgi için bkz. Bölgeler ve uç noktalar.
Bu konuda erişim kimlik bilgileri ortam değişkenlerinden alınır. Erişim kimlik bilgilerinin nasıl yapılandırılacağı hakkında daha fazla bilgi için bkz. Erişim kimlik bilgilerini yapılandırın.
Bu konu, bir OSS uç noktası ile bir OSSClient örneğinin nasıl oluşturulacağını göstermektedir. Özel etki alanı kullanma veya Security Token Service (STS) kimlik bilgileriyle kimlik doğrulama gibi alternatif yapılandırmalar için bkz. İstemciyi yapılandırın (Go SDK V1).
Aşağıdaki örnek kod, Go SDK 2.2.5 ve sonraki sürümlerde desteklenen özellikleri kullanır.
Örnek kod
Aşağıdaki kod, examplebucket adlı bir paketin depolama kapasitesini ve paketteki her depolama sınıfı için nesne sayısını ve depolama kapasitesini alır.
package main
import (
"log"
"github.com/aliyun/aliyun-oss-go-sdk/oss"
)
func main() {
// Obtain access credentials from environment variables.
provider, err := oss.NewEnvironmentVariableCredentialsProvider()
if err != nil {
log.Fatalf("Failed to get credentials from environment variables: %v", err)
}
// Create an OSSClient instance.
// Set yourEndpoint to the endpoint of the bucket. For example, for the China (Hangzhou) region, set the endpoint to https://oss-cn-hangzhou.aliyuncs.com. For other regions, specify the actual endpoint.
// Set yourRegion to the region where the bucket is located. For example, for the China (Hangzhou) region, set the region to cn-hangzhou. For other regions, specify the actual region.
clientOptions := []oss.ClientOption{oss.SetCredentialsProvider(&provider)}
clientOptions = append(clientOptions, oss.Region("yourRegion"))
// Set the signature version.
clientOptions = append(clientOptions, oss.AuthVersion(oss.AuthV4))
client, err := oss.New("yourEndpoint", "", "", clientOptions...)
if err != nil {
log.Fatalf("Failed to create new OSS client: %v", err)
}
// Specify the bucket name. For example, examplebucket.
bucketName := "examplebucket"
stat, err := client.GetBucketStat(bucketName)
if err != nil {
log.Fatalf("Failed to get bucket statistics for bucket '%s': %v", bucketName, err)
}
// Get the total storage capacity of the bucket in bytes.
log.Printf("Bucket Stat Storage: %d bytes\n", stat.Storage)
// Get the total number of objects in the bucket.
log.Printf("Bucket Stat Object Count: %d\n", stat.ObjectCount)
}
Yaygın depolama kapasitesi bilgileri
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Başvurular
Paket depolama kapasitesi API'si hakkında daha fazla bilgi için bkz. BucketStat.