Tüm Ürünler
Search
Belge Merkezi

Alibaba Cloud SDK:Zaman aşımı süresini yapılandırma

Son Güncelleme:Oct 07, 2026

Go için Alibaba Cloud SDK V1.0'da bağlantı ve okuma istekleri için zaman aşımı sürelerini, tekil isteklerden genel varsayılanlara kadar farklı düzeylerde yapılandırabilirsiniz.

Yöntemler

Not

Okuma zaman aşımı önceliği (en yüksekten en düşüğe): istek nesnesi > SDK istemcisi > Config nesnesi > çekirdek kitaplık varsayılanı > genel varsayılan.

Bağlantı zaman aşımı önceliği (en yüksekten en düşüğe): istek nesnesi > SDK istemcisi > genel varsayılan.

  • Varsayılan ayarları kullanın. Varsayılan bağlantı zaman aşımı 5.000 milisaniye, varsayılan okuma zaman aşımı ise 10.000 milisaniyedir.

    Önemli

    Go için Alibaba Cloud SDK'nın çekirdek kitaplığı, bazı API işlemleri için önceden tanımlanmış okuma zaman aşımı değerleri içerir. Önceden tanımlanmış bir değer varsa bu değer genel varsayılana göre önceliklidir. Daha fazla bilgi için bkz. api_timeout.go.

  • Bir istek nesnesi kullanın. Bu ayar yalnızca geçerli istek için uygulanır.

    import (
    	"fmt"
    	"os"
    	"time"
    
    	"github.com/aliyun/alibaba-cloud-sdk-go/sdk"
    	"github.com/aliyun/alibaba-cloud-sdk-go/sdk/auth/credentials"
    	ecs "github.com/aliyun/alibaba-cloud-sdk-go/services/ecs"
    )
    
    func main() {
    	config := sdk.NewConfig()
    	// Use the AccessKey ID and AccessKey secret of the Resource Access Management (RAM) user.
    	credential := credentials.NewAccessKeyCredential(os.Getenv("ALIBABA_CLOUD_ACCESS_KEY_ID"), os.Getenv("ALIBABA_CLOUD_ACCESS_KEY_SECRET"))
    	client, err := ecs.NewClientWithOptions("cn-hangzhou", config, credential)
    	if err != nil {
    		panic(err)
    	}
    
    	// Create a request.
    	request := ecs.CreateDescribeRegionsRequest()
    	// Configure a timeout period for the request. This setting takes effect only for the current request.
    	request.SetConnectTimeout(10 * time.Second)
    	request.SetReadTimeout(5 * time.Second)
    	// Specify HTTPS as the protocol.
    	request.Scheme = "https"
    	// The request parameters.
    	request.InstanceChargeType = "PrePaid" // The billing method of the instance.
    	request.ResourceType = "instance"      // The resource type.
    	// Send the request and obtain a response.
    	response, err := client.DescribeRegions(request)
    	if err != nil {
    		fmt.Print(err.Error())
    	}
    	fmt.Printf("response is %#v\n", response)
    }
  • Bir SDK istemcisini başlatın. Bu ayar, SDK istemcisi üzerinden gönderilen tüm istekler için geçerlidir.

    import (
    	"fmt"
    	"os"
    	"time"
    
    	"github.com/aliyun/alibaba-cloud-sdk-go/sdk"
    	"github.com/aliyun/alibaba-cloud-sdk-go/sdk/auth/credentials"
    	ecs "github.com/aliyun/alibaba-cloud-sdk-go/services/ecs"
    )
    
    func main() {
    	config := sdk.NewConfig()
    	// Use the AccessKey ID and AccessKey secret of the RAM user.
    	credential := credentials.NewAccessKeyCredential(os.Getenv("ALIBABA_CLOUD_ACCESS_KEY_ID"), os.Getenv("ALIBABA_CLOUD_ACCESS_KEY_SECRET"))
    	client, err := ecs.NewClientWithOptions("cn-hangzhou", config, credential)
    	if err != nil {
    		panic(err)
    	}
    	// Configure a timeout period on the SDK client. This setting takes effect on all requests that are sent by using the SDK client.
    	client.SetConnectTimeout(10 * time.Second)
    	client.SetReadTimeout(5 * time.Second)
    
    	// Create a request.
    	request := ecs.CreateDescribeRegionsRequest()
    	// Specify HTTPS as the protocol.
    	request.Scheme = "https"
    	// The request parameters.
    	request.InstanceChargeType = "PrePaid" // The billing method of the instance.
    	request.ResourceType = "instance"      // The resource type.
    	// Send the request and obtain a response.
    	response, err := client.DescribeRegions(request)
    	if err != nil {
    		fmt.Print(err.Error())
    	}
    	fmt.Printf("response is %#v\n", response)
    }
  • SDK istemcisini başlatırken bir Config nesnesi kullanın. Bu ayar, Config nesnesi ile başlatılan tüm SDK istemcileri için geçerlidir.

    import (
    	"fmt"
    	"os"
    	"time"
    
    	"github.com/aliyun/alibaba-cloud-sdk-go/sdk"
    	"github.com/aliyun/alibaba-cloud-sdk-go/sdk/auth/credentials"
    	ecs "github.com/aliyun/alibaba-cloud-sdk-go/services/ecs"
    )
    
    func main() {
    	config := sdk.NewConfig()
    	// Use a Config object to configure a timeout period.
    	config.Timeout = 5 * time.Second
    	// Use the AccessKey ID and AccessKey secret of the RAM user.
    	credential := credentials.NewAccessKeyCredential(os.Getenv("ALIBABA_CLOUD_ACCESS_KEY_ID"), os.Getenv("ALIBABA_CLOUD_ACCESS_KEY_SECRET"))
    	client, err := ecs.NewClientWithOptions("cn-hangzhou", config, credential)
    	if err != nil {
    		panic(err)
    	}
    
    	// Create a request.
    	request := ecs.CreateDescribeRegionsRequest()
    	// Specify HTTPS as the protocol.
    	request.Scheme = "https"
    	// The request parameters.
    	request.InstanceChargeType = "PrePaid" // The billing method of the instance.
    	request.ResourceType = "instance"      // The resource type.
    	// Send the request and obtain a response.
    	response, err := client.DescribeRegions(request)
    	if err != nil {
    		fmt.Print(err.Error())
    	}
    	fmt.Printf("response is %#v\n", response)
    }