provider

package
v1.0.7 Latest Latest
Warning

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

Go to latest
Published: Oct 29, 2026 License: MIT Imports: 16 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Binds a wire protocol to an endpoint, a credential and an HTTP retry policy

Index

Constants

View Source
const UserAgent = "icebath"

Sent when neither the protocol nor the provider names a user agent

Variables

This section is empty.

Functions

func RequestID

func RequestID(h http.Header) string

Request identifier named by any of the known headers

Types

type Attempt

type Attempt struct {
	URL      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

func (Attempt) OK

func (a Attempt) OK() bool

Reports whether the attempt returned a usable response

type Auth

type Auth interface {
	Apply(r *http.Request)
}

Attaches a credential to an outgoing request

type Bearer

type Bearer string

Credential sent as Authorization Bearer

func (Bearer) Apply

func (b Bearer) Apply(r *http.Request)

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

func (Directive) Clone

func (d Directive) Clone() Directive

Deep copy sharing nothing with the original

type Header struct {
	Name  string
	Value string
}

Credential sent in a named header such as x-api-key

func (Header) Apply

func (h Header) Apply(r *http.Request)

type None

type None struct{}

Credential for endpoints that need none

func (None) Apply

func (None) Apply(*http.Request)

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
}

Protocol plus everything the protocol leaves to the endpoint

func (*Provider) Complete

func (p *Provider) Complete(ctx context.Context, req protocol.Request) (protocol.Response, error)

Sends one turn without streaming and decodes the complete response

func (*Provider) Do

func (p *Provider) Do(ctx context.Context, call protocol.Call) (*http.Response, error)

Issues any call against the endpoint with auth and retries, returning the 2xx response unread

func (*Provider) Stream

Sends one turn and yields the protocol events of its streamed response

type Query

type Query struct {
	Name  string
	Value string
}

Credential sent as a named query parameter

func (Query) Apply

func (q Query) Apply(r *http.Request)

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

func ParseRateLimit(h http.Header) RateLimit

Reads the rate limit headers of every supported vendor into one view

func (RateLimit) Known

func (r RateLimit) Known() bool

Reports whether any field was filled in

type Refresher

type Refresher interface {
	Refresh(ctx context.Context) error
}

Auth that must do work before it can sign, such as loading or refreshing a credential

type Starter

type Starter interface {
	Begin(Attempt)
}

Observer that also hears each attempt as it starts, before anything comes back

Directories

Path Synopsis
AWS Signature Version 4 credential carrier for Bedrock and other AWS endpoints
AWS Signature Version 4 credential carrier for Bedrock and other AWS endpoints

Jump to

Keyboard shortcuts

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