Documentation
¶
Index ¶
- func Run(cfg Config) error
- type AccountHandler
- type AccountStore
- func (s *AccountStore) Create(a DevAccount) DevAccount
- func (s *AccountStore) Delete(id int64) bool
- func (s *AccountStore) First() *DevAccount
- func (s *AccountStore) Get(id int64) *DevAccount
- func (s *AccountStore) List() []DevAccount
- func (s *AccountStore) Update(id int64, a DevAccount) *DevAccount
- type Config
- type DevAccount
- type ProxyHandler
- type SchedulePolicy
- type Scheduler
- func (s *Scheduler) IsRetryable(outcome sdk.ForwardOutcome, err error) bool
- func (s *Scheduler) Policy() SchedulePolicy
- func (s *Scheduler) ReportResult(accountID int64, outcome sdk.ForwardOutcome)
- func (s *Scheduler) Select() *DevAccount
- func (s *Scheduler) SetPinned(accountID int64)
- func (s *Scheduler) SetPolicy(policy SchedulePolicy)
- func (s *Scheduler) Status() map[string]any
- type SchedulerHandler
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type AccountHandler ¶
type AccountHandler struct {
// contains filtered or unexported fields
}
AccountHandler 处理 /api/accounts 路由
func (*AccountHandler) ServeHTTP ¶
func (h *AccountHandler) ServeHTTP(w http.ResponseWriter, r *http.Request)
type AccountStore ¶
type AccountStore struct {
// contains filtered or unexported fields
}
AccountStore JSON 文件存储
func (*AccountStore) Update ¶
func (s *AccountStore) Update(id int64, a DevAccount) *DevAccount
Update 更新账号
type Config ¶
type Config struct {
Plugin sdk.GatewayPlugin // 必填:网关插件实例
Addr string // 监听地址,默认 ":18080"
DataDir string // 数据目录,默认 "./devdata"
ExtraRoutes func(mux *http.ServeMux, store *AccountStore) // 插件自定义路由(如 OAuth)
SchedulePolicy SchedulePolicy // 调度策略,默认 "none"(直连第一个账号)
}
Config devserver 配置
type DevAccount ¶
type DevAccount struct {
ID int64 `json:"id"`
Name string `json:"name"`
AccountType string `json:"account_type"`
Credentials map[string]string `json:"credentials"`
ProxyURL string `json:"proxy_url,omitempty"`
Weight int `json:"weight,omitempty"` // 调度权重,默认 1
}
DevAccount 开发用账号(复用 sdk.Account 字段 + 额外元数据)
type ProxyHandler ¶
type ProxyHandler struct {
// contains filtered or unexported fields
}
ProxyHandler 将请求代理给插件
func (*ProxyHandler) ServeHTTP ¶
func (p *ProxyHandler) ServeHTTP(w http.ResponseWriter, r *http.Request)
type SchedulePolicy ¶
type SchedulePolicy string
SchedulePolicy 调度策略
const ( ScheduleNone SchedulePolicy = "none" // 直连指定账号(默认第一个) ScheduleWeightedRR SchedulePolicy = "weighted_rr" // 加权轮询 + failover )
type Scheduler ¶
type Scheduler struct {
// contains filtered or unexported fields
}
Scheduler 账号调度器
func NewScheduler ¶
func NewScheduler(store *AccountStore, policy SchedulePolicy) *Scheduler
NewScheduler 创建调度器
func (*Scheduler) IsRetryable ¶
func (s *Scheduler) IsRetryable(outcome sdk.ForwardOutcome, err error) bool
IsRetryable 判断转发结果是否可 failover。
func (*Scheduler) ReportResult ¶
func (s *Scheduler) ReportResult(accountID int64, outcome sdk.ForwardOutcome)
ReportResult 上报转发结果,用于标记冷却。
func (*Scheduler) SetPolicy ¶
func (s *Scheduler) SetPolicy(policy SchedulePolicy)
SetPolicy 运行时切换策略
type SchedulerHandler ¶
type SchedulerHandler struct {
// contains filtered or unexported fields
}
SchedulerHandler 调度管理 API
func (*SchedulerHandler) ServeHTTP ¶
func (h *SchedulerHandler) ServeHTTP(w http.ResponseWriter, r *http.Request)
Click to show internal directories.
Click to hide internal directories.