Documentation
¶
Overview ¶
Binds a wire protocol to an endpoint, a credential and an HTTP retry policy
Index ¶
- Constants
- func LabelFrom(ctx context.Context) string
- func RequestID(h http.Header) string
- func WithLabel(ctx context.Context, label string) context.Context
- type Attempt
- type Auth
- type Bearer
- type Directive
- type Header
- type None
- type Observer
- type Provider
- type Query
- type RateLimit
- type Refresher
- type StallError
- type Starter
Constants ¶
const ( DialTimeout = 10 * time.Second HeaderTimeout = 10 * time.Minute StallTimeout = 10 * time.Minute )
Bounds on a call the endpoint can otherwise hold open forever, connection setup, the wait for the response headers and the longest silence a body may fall into between bytes
const UserAgent = "icebath"
Sent when neither the protocol nor the provider names a user agent
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Attempt ¶
type Attempt struct {
URL string
// Label the caller set on the context, such as the run the call serves
Label string
Started time.Time
Duration time.Duration
Status int
// Transport or decoded wire failure, nil on a 2xx
Err error
// Pause before the next attempt, zero when this one was the last
Wait time.Duration
// Pause the endpoint asked for through Retry-After
RetryAfter time.Duration
RequestID string
RateLimit RateLimit
}
One HTTP attempt of a call with what came back and how long the provider will wait before the next
type Directive ¶
type Directive struct {
Header http.Header `json:"header,omitempty"`
Extra map[string]json.RawMessage `json:"extra,omitempty"`
}
Headers and body fields sent with a turn that asks for one directive
type Observer ¶
type Observer interface {
Observe(Attempt)
}
Receives every attempt a provider makes
type Provider ¶
type Provider struct {
Name string
Protocol protocol.Protocol
BaseURL string
Auth Auth
// Static headers every request carries after the protocol headers
Header http.Header
// Static query parameters every request carries
Query url.Values
// Request fields merged into every turn beneath the fields the request itself carries
Extra map[string]json.RawMessage
// Headers and body fields laid over every turn, how the endpoint hears what the profile asks of it
Directives []Directive
// Receives every attempt with its status, headers and backoff
Observer Observer
// Bounds on the wait for the headers and on silence inside the body, the package defaults when zero
HeaderTimeout time.Duration
StallTimeout time.Duration
}
Protocol plus everything the protocol leaves to the endpoint
type RateLimit ¶
type RateLimit struct {
Requests int
RequestsRemaining int
Tokens int
TokensRemaining int
InputTokens int
InputRemaining int
OutputTokens int
OutputRemaining int
Reset time.Duration
}
What the endpoint reported about its quota on one response, zero where it said nothing
func ParseRateLimit ¶
Reads the rate limit headers of every supported vendor into one view
type Refresher ¶
Auth that must do work before it can sign, such as loading or refreshing a credential
type StallError ¶ added in v1.0.11
type StallError struct {
Provider string
// Whether the silence fell before the headers or inside the body
Headers bool
After time.Duration
}
Error of a call the endpoint left silent for longer than the bound
func (*StallError) Error ¶ added in v1.0.11
func (e *StallError) Error() string