Documentation
¶
Overview ¶
Package pool runs the single-pass credential failover shared by every backend: each key is tried at most once in pool order, the first success wins, otherwise the last error is returned. Streaming attempts stop failover once the first byte reaches the client.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var NoCredentials = errors.New("no credentials available")
NoCredentials is returned for an empty pool.
Functions ¶
func Run ¶
func Run[T any](ctx context.Context, log *slog.Logger, creds []*models.Credential, tracker UsageTracker, attempt func(context.Context, *models.Credential) (T, error), isFatal func(error) bool) (T, error)
Run tries one attempt per credential in pool order and returns the first success. Fatal attempt errors (isFatal) stop the pool immediately: they are identical for every key.
func RunStream ¶
func RunStream(ctx context.Context, log *slog.Logger, w io.Writer, creds []*models.Credential, tracker UsageTracker, attempt func(context.Context, *models.Credential, io.Writer) error, isFatal func(error) bool) error
RunStream is Run for streaming calls. Failover continues only while no byte reached the client; afterwards the stream belongs to one upstream and ends with its error.
Types ¶
type UsageTracker ¶
UsageTracker records per-credential outcomes. Implemented by the credential service; backends receive it by injection. Limit state lives in the exhausted store, never here: failures only feed usage statistics.