Help us shape the future of Go! Take the 2026 Go Developer Survey

client

package
v5.15.2 Latest Latest
Warning

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

Go to latest
Published: Oct 28, 2026 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DefaultRetryCondition

func DefaultRetryCondition(resp *http.Response, err error) bool

DefaultRetryCondition determines if a request should be retried

func WithContext

func WithContext(ctx context.Context, req *http.Request) *http.Request

WithContext creates a new request with context for better cancellation handling

Types

type Client

type Client struct {
	AuthContext  context.Context
	Bearer       string
	Organization string
	Instance     *openapi.APIClient

	// RulesMutex serialises rule modifications across resources that operate on a shared backend file
	RulesMutex *sync.Mutex
	// contains filtered or unexported fields
}

func New

func New(bearer string, organization string) *Client

Rather than the practioner providing an organization for all resources managed by the terraform instance we scope the data client to an organization with provider configuration.

func NewWithBaseURL

func NewWithBaseURL(bearer string, organization string, baseURL string) *Client

NewWithBaseURL creates a new client with custom base URL

func NewWithOptions

func NewWithOptions(bearer string, organization string, opts *ClientOptions) *Client

NewWithOptions creates a new client with custom options

func NewWithRateLimit

func NewWithRateLimit(bearer string, organization string, config *RateLimitConfig) *Client

NewWithRateLimit creates a new client with custom rate limiting configuration

func NewWithRateLimitAndBaseURL

func NewWithRateLimitAndBaseURL(bearer string, organization string, config *RateLimitConfig, baseURL string) *Client

NewWithRateLimitAndBaseURL creates a new client with both rate limiting and base URL configuration

func (*Client) Close

func (c *Client) Close()

Close cleans up client resources

func (*Client) GetRateLimitConfig

func (c *Client) GetRateLimitConfig() *RateLimitConfig

GetRateLimitConfig returns the current rate limit configuration

func (*Client) UpdateRateLimitConfig

func (c *Client) UpdateRateLimitConfig(config *RateLimitConfig)

UpdateRateLimitConfig updates the rate limit configuration Note: This requires creating a new HTTP client instance

type ClientOptions

type ClientOptions struct {
	RateLimitConfig *RateLimitConfig
	HTTPClient      *http.Client
	BaseURL         string
}

ClientOptions allows customization of the client

type RateLimitConfig

type RateLimitConfig struct {
	// Maximum number of requests per second
	RequestsPerSecond float64
	// Maximum number of retry attempts
	MaxRetries int
	// Base delay for exponential backoff (in milliseconds)
	BaseDelay time.Duration
	// Maximum delay for exponential backoff (in milliseconds)
	MaxDelay time.Duration
	// Whether to add jitter to delays
	EnableJitter bool
	// Custom retry condition function
	RetryCondition func(*http.Response, error) bool
	// Per-request timeout (optional, for fine-grained timeout control)
	RequestTimeout time.Duration
	// Retries allowed for the rules API's advisory 409 lock, counted separately
	// from MaxRetries: the lock is expected contention, not a fault, and a
	// project with many rules changing at once needs a longer wait.
	MaxLockRetries int
	// Minimum delay before re-sending after a rules lock 409
	LockRetryDelay time.Duration
}

RateLimitConfig holds configuration for rate limiting

func DefaultRateLimitConfig

func DefaultRateLimitConfig() *RateLimitConfig

DefaultRateLimitConfig returns sensible defaults for rate limiting

type RateLimitedHTTPClient

type RateLimitedHTTPClient struct {
	*http.Client
	// contains filtered or unexported fields
}

RateLimitedHTTPClient wraps an HTTP client with rate limiting

func NewRateLimitedHTTPClient

func NewRateLimitedHTTPClient(config *RateLimitConfig) *RateLimitedHTTPClient

NewRateLimitedHTTPClient creates a new HTTP client with rate limiting

func (*RateLimitedHTTPClient) Close

func (c *RateLimitedHTTPClient) Close()

Close cleans up resources

type RateLimitedRoundTripper

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

RateLimitedRoundTripper implements http.RoundTripper with rate limiting and retry logic

func NewRateLimitedRoundTripper

func NewRateLimitedRoundTripper(transport http.RoundTripper, config *RateLimitConfig) *RateLimitedRoundTripper

NewRateLimitedRoundTripper creates a new rate-limited round tripper

func (*RateLimitedRoundTripper) Close

func (rt *RateLimitedRoundTripper) Close()

Close cleans up the rate limiter resources

func (*RateLimitedRoundTripper) RoundTrip

func (rt *RateLimitedRoundTripper) RoundTrip(req *http.Request) (*http.Response, error)

RoundTrip implements the http.RoundTripper interface with rate limiting and retries

Jump to

Keyboard shortcuts

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