balancer

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Sep 27, 2026 License: MIT Imports: 4 Imported by: 0 modules, 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

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AccountPool

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

AccountPool 在健康账号之间调度请求并维护显式会话粘性

func NewAccountPool

func NewAccountPool(cooldown time.Duration, sessionTTL time.Duration) *AccountPool

NewAccountPool 创建账号池

func (*AccountPool) Add

func (p *AccountPool) Add(client *gemini.Client, accountID string)

Add 添加一个已经完成协议初始化的账号

func (*AccountPool) AddUnavailable

func (p *AccountPool) AddUnavailable(accountID string)

AddUnavailable 记录一个启动失败的账号

func (*AccountPool) BindSession

func (p *AccountPool) BindSession(sessionKey string, accountID string)

BindSession 将成功响应标识绑定到产生它的账号

func (*AccountPool) ClearSession

func (p *AccountPool) ClearSession(sessionKey string)

ClearSession 结束显式会话的账号粘性

func (*AccountPool) Clients

func (p *AccountPool) Clients() []*gemini.Client

Clients 返回当前健康客户端快照

func (*AccountPool) HasModel

func (p *AccountPool) HasModel(modelID string) bool

HasModel 报告已初始化账号是否发现目标模型

func (*AccountPool) HasReadyModel

func (p *AccountPool) HasReadyModel(modelID string) bool

HasReadyModel 报告当前是否有健康账号可以运行目标模型

func (*AccountPool) NextForModel

func (p *AccountPool) NextForModel(sessionKey string, modelID string) (*gemini.Client, string)

NextForModel 为新请求选择真正支持目标模型的健康账号

func (*AccountPool) NextForModelExcluding

func (p *AccountPool) NextForModelExcluding(sessionKey string, modelID string, excludedAccountIDs map[string]struct{}) (*gemini.Client, string)

NextForModelExcluding 为无会话重试选择未排除的同能力账号

func (*AccountPool) ReportFailure

func (p *AccountPool) ReportFailure(accountID string)

ReportFailure 将账号移入冷却

func (*AccountPool) ReportSuccess

func (p *AccountPool) ReportSuccess(accountID string)

ReportSuccess 清除账号的连续失败状态

func (*AccountPool) Size

func (p *AccountPool) Size() int

Size 返回当前可接收请求的账号数量

func (*AccountPool) Status

func (p *AccountPool) Status() PoolStatus

Status 返回账号池健康快照

func (*AccountPool) Usage

Usage 并发读取全部已初始化账号的官网用量

type AccountStatus

type AccountStatus struct {
	AccountID        string     `json:"account_id"`
	State            string     `json:"state"`
	LastUsed         *time.Time `json:"last_used,omitempty"`
	CooldownUntil    *time.Time `json:"cooldown_until,omitempty"`
	ConsecutiveFails int        `json:"consecutive_failures"`
}

AccountStatus 是健康检查使用的脱敏账号状态

type AccountUsageStatus

type AccountUsageStatus struct {
	AccountID string            `json:"account_id"`
	State     string            `json:"state"`
	Usage     *gemini.UsageInfo `json:"usage,omitempty"`
	Error     string            `json:"error,omitempty"`
}

AccountUsageStatus 表示单个账号的实时官网用量

type PoolStatus

type PoolStatus struct {
	Total       int             `json:"total"`
	Available   int             `json:"available"`
	CoolingDown int             `json:"cooling_down"`
	Unavailable int             `json:"unavailable"`
	Accounts    []AccountStatus `json:"accounts"`
}

PoolStatus 汇总账号池状态

type PoolUsageStatus

type PoolUsageStatus struct {
	Accounts []AccountUsageStatus `json:"accounts"`
}

PoolUsageStatus 汇总账号池实时官网用量

Jump to

Keyboard shortcuts

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