client

package module
v0.2.10 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 8, 2023 License: Apache-2.0 Imports: 11 Imported by: 24

README

api-client-go

Go Reference Tests Go Report Card

さくらのクラウド向けAPI/HTTPクライアントライブラリ

License

sacloud/api-client-go Copyright (C) 2022-2023 The sacloud/api-client-go Authors.

This project is published under Apache 2.0 License.

Documentation

Index

Constants

View Source
const Version = "0.2.10"

Version バージョン

Variables

View Source
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

This section is empty.

Types

type Factory

type Factory struct {
	// contains filtered or unexported fields
}

Factory client.HttpRequestDoerを作成して返すファクトリー

func NewFactory

func NewFactory(options ...*Options) *Factory

NewFactory 指定のオプションでFactoryを生成する

func (*Factory) NewHttpRequestDoer

func (f *Factory) NewHttpRequestDoer() HttpRequestDoer

NewHttpRequestDoer オプションを反映したsacloud向けのHTTPクライアントを生成して返す

func (*Factory) Options

func (f *Factory) Options() *Options

Options Doerの生成で用いるOptionsを返す

type HttpRequestDoer

type HttpRequestDoer interface {
	Do(req *http.Request) (*http.Response, error)
}

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

func DefaultOption() (*Options, error)

DefaultOption 環境変数、プロファイルからCallerOptionsを組み立てて返す

プロファイルは環境変数`SAKURACLOUD_PROFILE`または`USACLOUD_PROFILE`でプロファイル名が指定されていればそちらを優先し、 未指定の場合は通常のプロファイル処理(~/.usacloud/currentファイルから読み込み)される。 同じ項目を複数箇所で指定していた場合、環境変数->プロファイルの順で上書きされたものが返される

func DefaultOptionWithProfile

func DefaultOptionWithProfile(profileName string) (*Options, error)

DefaultOptionWithProfile 環境変数、プロファイルからCallerOptionsを組み立てて返す

プロファイルは引数を優先し、空の場合は環境変数`SAKURACLOUD_PROFILE`または`USACLOUD_PROFILE`が利用され、 それも空の場合は通常のプロファイル処理(~/.usacloud/currentファイルから読み込み)される。 同じ項目を複数箇所で指定していた場合、環境変数->プロファイルの順で上書きされたものが返される

func MergeOptions

func MergeOptions(opts ...*Options) *Options

MergeOptions 指定のCallerOptionsの非ゼロ値フィールドをoのコピーにマージして返す

func OptionsFromEnv

func OptionsFromEnv() *Options

OptionsFromEnv 環境変数からCallerOptionsを組み立てて返す

func OptionsFromProfile

func OptionsFromProfile(profileName string) (*Options, error)

OptionsFromProfile 指定のプロファイルからCallerOptionsを組み立てて返す

プロファイルは引数を優先し、空の場合は環境変数`SAKURACLOUD_PROFILE`または`USACLOUD_PROFILE`が利用され、 それも空の場合は通常のプロファイル処理(~/.usacloud/currentファイルから読み込み)される。

func (*Options) ProfileConfigValue

func (o *Options) ProfileConfigValue() *profile.ConfigValue

ProfileConfigValue プロファイルから読み込んだprofile.ConfigValueを返す

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL