admin

package
v0.1.6 Latest Latest
Warning

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

Go to latest
Published: Oct 23, 2026 License: MIT Imports: 26 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

Overview

Package admin 提供管理端接口:状态与事件流、账号、模型、请求、日志、用量与设置

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Mount

func Mount(router *gin.Engine, deps Deps)

Mount 在 /api 下注册管理端接口

func NotFound

func NotFound(c *gin.Context)

NotFound 以管理端错误体返回未知的 /api 路径

Types

type ConfigUpdate

type ConfigUpdate struct {
	ProxyAPIKey      *string `json:"proxy_api_key"`
	Proxy            *string `json:"proxy"`
	SaveHistory      *bool   `json:"save_history"`
	ModelMapping     *string `json:"model_mapping"`
	AccountCooldown  *string `json:"account_cooldown"`
	SessionTTL       *string `json:"session_ttl"`
	InitTimeout      *string `json:"init_timeout"`
	LogLevel         *string `json:"log_level"`
	RequestBodyLog   *bool   `json:"request_body_log"`
	LogFile          *bool   `json:"log_file"`
	LogMaxTotalMB    *int    `json:"log_max_total_mb"`
	Concurrency      *int    `json:"per_account_concurrency"`
	RoutingStrategy  *string `json:"routing_strategy"`
	AdminAuthEnabled *bool   `json:"admin_auth_enabled"`
	AdminUsername    *string `json:"admin_username"`
	AdminPassword    *string `json:"admin_password"`
	ListenAddr       *string `json:"listen_addr"`
	AuthStates       *string `json:"auth_states"`
	LogFormat        *string `json:"log_format"`
}

ConfigUpdate 是设置页提交的修改,nil 表示不修改

type Deps

type Deps struct {
	Pool       *balancer.AccountPool
	Accounts   *accounts.Manager
	Store      *requestdb.Store
	Settings   *Settings
	Version    string
	StartedAt  time.Time
	ListenAddr string
	Desktop    bool
	DataDir    string
	Updates    UpdateService
	// Stopping 在服务开始停机时关闭,已打开的事件流随之结束
	Stopping <-chan struct{}
}

Deps 是管理端使用的运行期组件与进程信息

type ServiceConfig

type ServiceConfig struct {
	ProxyAPIKey      string   `json:"proxy_api_key"`
	Proxy            string   `json:"proxy"`
	SaveHistory      bool     `json:"save_history"`
	ModelMapping     string   `json:"model_mapping"`
	AccountCooldown  string   `json:"account_cooldown"`
	SessionTTL       string   `json:"session_ttl"`
	InitTimeout      string   `json:"init_timeout"`
	LogLevel         string   `json:"log_level"`
	RequestBodyLog   bool     `json:"request_body_log"`
	LogFile          bool     `json:"log_file"`
	LogMaxTotalMB    int      `json:"log_max_total_mb"`
	Concurrency      int      `json:"per_account_concurrency"`
	RoutingStrategy  string   `json:"routing_strategy"`
	AdminAuthEnabled bool     `json:"admin_auth_enabled"`
	AdminUsername    string   `json:"admin_username"`
	AdminPasswordSet bool     `json:"admin_password_set"`
	ListenAddr       string   `json:"listen_addr"`
	AuthStates       string   `json:"auth_states"`
	LogFormat        string   `json:"log_format"`
	ActiveListenAddr string   `json:"active_listen_addr"`
	RestartRequired  bool     `json:"restart_required"`
	RestartFields    []string `json:"restart_fields"`
}

ServiceConfig 是管理端设置页的配置视图

type Settings

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

Settings 保存管理端可修改的配置,保存时写回 .env 并即时应用可热更新的项

func NewSettings

func NewSettings(envPath string, cfg config.Config, apply func(config.Config)) *Settings

NewSettings 以启动时生效的配置创建设置,apply 应用可热更新的项

func (*Settings) APIKey

func (s *Settings) APIKey() string

APIKey 返回当前生效的公开 API key,多个 key 以逗号分隔

func (*Settings) Snapshot

func (s *Settings) Snapshot() config.Config

Snapshot 返回当前配置

func (*Settings) Update

func (s *Settings) Update(update ConfigUpdate) error

Update 校验修改,写回 .env 并应用可热更新的项

func (*Settings) View

func (s *Settings) View() ServiceConfig

View 返回设置页的配置视图

type UpdateConflict added in v0.1.6

type UpdateConflict string

UpdateConflict 表示当前状态不能安装更新

func (UpdateConflict) Error added in v0.1.6

func (err UpdateConflict) Error() string

type UpdateService added in v0.1.6

type UpdateService interface {
	UpdateStatus(ctx context.Context, refresh bool) (UpdateStatus, error)
	ApplyUpdate(ctx context.Context) (UpdateStatus, error)
}

UpdateService 检查并安装 GitHub 上的新发行版本

type UpdateStatus added in v0.1.6

type UpdateStatus struct {
	Current     string    `json:"current"`
	Latest      string    `json:"latest,omitempty"`
	Available   bool      `json:"available"`
	Mode        string    `json:"mode"`
	Notes       string    `json:"notes,omitempty"`
	URL         string    `json:"url,omitempty"`
	PublishedAt time.Time `json:"published_at,omitzero"`
	CheckedAt   time.Time `json:"checked_at,omitzero"`
	Error       string    `json:"error,omitempty"`
	Updating    bool      `json:"updating"`
}

UpdateStatus 是当前版本与 GitHub 最新发行版本,Mode 为 binary(可原地更新)、container(随镜像更新)或 development(源码构建)

Jump to

Keyboard shortcuts

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