Documentation
¶
Index ¶
- Constants
- Variables
- func IsNotFoundError(err error) bool
- type APIError
- type Client
- type ClientParam
- func WithApiKeys(accessToken string, secretToken string) ClientParam
- func WithDisableEnv(disable bool) ClientParam
- func WithDisableProfile(disable bool) ClientParam
- func WithHTTPClient(client *http.Client) ClientParam
- func WithOptions(options *Options) ClientParam
- func WithProfile(profile string) ClientParam
- func WithUserAgent(ua string) ClientParam
- type ClientParams
- type Factory
- type HttpRequestDoer
- type Options
Constants ¶
const Version = "0.3.5"
Version バージョン
Variables ¶
var DefaultUserAgent = fmt.Sprintf( "api-client-go/v%s (%s/%s; +https://github.com/sacloud/api-client-go) %s", Version, runtime.GOOS, runtime.GOARCH, sacloudhttp.DefaultUserAgent, )
DefaultUserAgent デフォルトのユーザーエージェント
Functions ¶
func IsNotFoundError ¶ added in v0.3.1
Types ¶
type Client ¶ added in v0.3.0
type Client struct {
// APIRootURL APIのリクエスト先URLプレフィックス
APIRootURL string
// contains filtered or unexported fields
}
Client APIクライアント
func NewClient ¶ added in v0.3.0
func NewClient(apiUrl string, params ...ClientParam) (*Client, error)
Clientを初期化してから返す。WithXXXを使って特定の設定を初期化可能
func NewClientWithParams ¶ added in v0.3.0
func NewClientWithParams(params *ClientParams) (*Client, error)
設定したいパラメータが多い場合は直接ClientParamsを初期化して渡す
func (*Client) NewHttpRequestDoer ¶ added in v0.3.0
func (c *Client) NewHttpRequestDoer() HttpRequestDoer
type ClientParam ¶ added in v0.3.0
type ClientParam func(*ClientParams)
func WithApiKeys ¶ added in v0.3.0
func WithApiKeys(accessToken string, secretToken string) ClientParam
func WithDisableEnv ¶ added in v0.3.0
func WithDisableEnv(disable bool) ClientParam
func WithDisableProfile ¶ added in v0.3.0
func WithDisableProfile(disable bool) ClientParam
func WithHTTPClient ¶ added in v0.3.3
func WithHTTPClient(client *http.Client) ClientParam
WithHTTPClient allows setting a custom http.Client (e.g., from httptest)
func WithOptions ¶ added in v0.3.0
func WithOptions(options *Options) ClientParam
func WithProfile ¶ added in v0.3.0
func WithProfile(profile string) ClientParam
func WithUserAgent ¶ added in v0.3.0
func WithUserAgent(ua string) ClientParam
type ClientParams ¶ added in v0.3.0
type ClientParams struct {
// APIのリクエスト先URLプレフィックス
APIRootURL string
// APIキー群
Token string
Secret string
// クライアントから送られるユーザエージェント
UserAgent string
// Options HTTPクライアント関連オプション
Options *Options
// Profile usacloud互換プロファイル名
Profile string
// usacloud互換プロファイルからの設定読み取りを無効化
DisableProfile bool
// 環境変数からの設定読み取りを無効化
DisableEnv bool
// カスタムHTTPクライアント (例: httptest.NewServer().Client())
HTTPClient *http.Client
}
SDKライブラリから設定するパラメータ。WithXXXを使って特定のパラメータだけ設定可能
type Factory ¶
type Factory struct {
// contains filtered or unexported fields
}
Factory client.HttpRequestDoerを作成して返すファクトリー
func (*Factory) NewHttpRequestDoer ¶
func (f *Factory) NewHttpRequestDoer() HttpRequestDoer
NewHttpRequestDoer オプションを反映したsacloud向けのHTTPクライアントを生成して返す
type HttpRequestDoer ¶
HttpRequestDoer API/HTTPクライアントインターフェース
type Options ¶
type Options struct {
// AccessToken APIキー:トークン
AccessToken string
// AccessTokenSecret APIキー:シークレット
AccessTokenSecret string
// AcceptLanguage APIリクエスト時のAccept-Languageヘッダーの値
AcceptLanguage string
// Gzip APIリクエストでgzipを有効にするかのフラグ
Gzip bool
// HttpClient APIリクエストで使用されるHTTPクライアント
//
// 省略した場合はhttp.DefaultClientが使用される
HttpClient *http.Client
// HttpRequestTimeout HTTPリクエストのタイムアウト秒数
HttpRequestTimeout int
// HttpRequestRateLimit 1秒あたりの上限リクエスト数
HttpRequestRateLimit int
// RetryMax リトライ上限回数
RetryMax int
// RetryWaitMax リトライ待ち秒数(最大)
RetryWaitMax int
// RetryWaitMin リトライ待ち秒数(最小)
RetryWaitMin int
// UserAgent ユーザーエージェント
UserAgent string
// Trace HTTPリクエスト/レスポンスのトレースログ(ダンプ)出力
Trace bool
// TraceOnlyError HTTPリクエスト/レスポンスのトレースログ(ダンプ)出力で非200番台のレスポンス時のみ出力する
TraceOnlyError bool
// RequestCustomizers リクエスト前に*http.Requestのカスタマイズを行うためのfunc
RequestCustomizers []sacloudhttp.RequestCustomizer
// CheckRetryFunc リトライすべきか判定するためのfunc
//
// CheckRetryStatusCodesより優先される
CheckRetryFunc func(ctx context.Context, resp *http.Response, err error) (bool, error)
// CheckRetryStatusCodes リトライすべきステータスコード
//
// CheckRetryFuncが指定されていない、かつこの値が指定されている場合、指定のステータスコードを持つレスポンスを受け取ったらリトライする
CheckRetryStatusCodes []int
// contains filtered or unexported fields
}
Options sacloudhttp.Clientを作成する際のオプション
func DefaultOption ¶
DefaultOption 環境変数、プロファイルからCallerOptionsを組み立てて返す
プロファイルは環境変数`SAKURA_PROFILE`または`SAKURACLOUD_PROFILE`/`USACLOUD_PROFILE`でプロファイル名が指定されていればそちらを優先し、 未指定の場合は通常のプロファイル処理(~/.usacloud/currentファイルから読み込み)される。 同じ項目を複数箇所で指定していた場合、環境変数->プロファイルの順で上書きされたものが返される
func DefaultOptionWithProfile ¶
DefaultOptionWithProfile 環境変数、プロファイルからCallerOptionsを組み立てて返す
プロファイルは引数を優先し、空の場合は環境変数`SAKURA_PROFILE`または`SAKURACLOUD_PROFILE`/`USACLOUD_PROFILE`が利用され、 それも空の場合は通常のプロファイル処理(~/.usacloud/currentファイルから読み込み)される。 同じ項目を複数箇所で指定していた場合、環境変数->プロファイルの順で上書きされたものが返される
func MergeOptions ¶
MergeOptions 指定のCallerOptionsの非ゼロ値フィールドをoのコピーにマージして返す
func OptionsFromProfile ¶
OptionsFromProfile 指定のプロファイルからCallerOptionsを組み立てて返す
プロファイルは引数を優先し、空の場合は環境変数`SAKURA_PROFILE`または`SAKURACLOUD_PROFILE`/`USACLOUD_PROFILE`が利用され、 それも空の場合は通常のプロファイル処理(~/.usacloud/currentファイルから読み込み)される。
func (*Options) ProfileConfigValue ¶
func (o *Options) ProfileConfigValue() *profile.ConfigValue
ProfileConfigValue プロファイルから読み込んだprofile.ConfigValueを返す