pool

package
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Sep 25, 2026 License: MIT Imports: 6 Imported by: 0

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

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

type UsageTracker interface {
	UpdateUsage(id string, success bool) error
}

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.

Jump to

Keyboard shortcuts

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