项目作者: yandex-cloud

项目描述 :
Yandex.Cloud Go SDK
高级语言: Go
项目地址: git://github.com/yandex-cloud/go-sdk.git
创建时间: 2018-09-21T14:27:54Z
项目社区:https://github.com/yandex-cloud/go-sdk

开源协议:MIT License

下载


Yandex.Cloud Go SDK

GoDoc
CircleCI

Go SDK for Yandex.Cloud services.

NOTE: SDK is under development, and may make
backwards-incompatible changes.

Installation

  1. go get github.com/yandex-cloud/go-sdk

Example usages

Initializing SDK

  1. sdk, err := ycsdk.Build(ctx, ycsdk.Config{
  2. Credentials: ycsdk.OAuthToken(token),
  3. })
  4. if err != nil {
  5. log.Fatal(err)
  6. }

Retries

SDK provide built-in retry policy, that supports exponential backoff and jitter, and also retry budget.
It’s necessary to avoid retry amplification.

  1. import (
  2. ...
  3. ycsdk "github.com/yandex-cloud/go-sdk"
  4. "github.com/yandex-cloud/go-sdk/pkg/retry/v1"
  5. )
  6. ...
  7. retriesDialOption, err := retry.DefaultRetryDialOption()
  8. if err != nil {
  9. log.Fatal(err)
  10. }
  11. _, err = ycsdk.Build(
  12. ctx,
  13. ycsdk.Config{
  14. Credentials: ycsdk.OAuthToken(*token),
  15. },
  16. retriesDialOption,
  17. )

SDK provide different modes for retry throttling policy:

  • persistent is suitable when you use SDK in any long-lived application, when SDK instance will live long enough for manage budget;
  • temporary is suitable when you use SDK in any short-lived application, e.g. scripts or CI/CD.

By default, SDK will use temporary mode, but you can change it through functional option.

More examples

More examples can be found in examples dir.