config

package
v0.1.7 Latest Latest
Warning

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

Go to latest
Published: Nov 8, 2026 License: MIT Imports: 14 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

View Source
const MinLogTotalMB = 20

MinLogTotalMB 是日志目录总量上限的最小值,容纳当前文件与一个轮转文件

Variables

View Source
var Defaults = map[string]string{
	"LISTEN_ADDR": "127.0.0.1:8007", "GEMINI_AUTH_STATES": "auth", "PROXY_API_KEY": "", "PROXY": "",
	"ACCOUNT_COOLDOWN": "2m", "SESSION_TTL": "30m", "INIT_TIMEOUT": "20s", "MODEL_MAPPING": "", "GEMINI_SAVE_HISTORY": "false",
	"LOG_LEVEL": "info", "LOG_FORMAT": "text", "REQUEST_BODY_LOG": "false", "LOG_FILE": "true", "LOG_MAX_TOTAL_MB": "500",
	"PER_ACCOUNT_CONCURRENCY": "1", "ROUTING_STRATEGY": "round-robin", "ADMIN_AUTH_ENABLED": "false", "ADMIN_USERNAME": "admin",
	"ADMIN_PASSWORD": "", "API_KEY_ACCOUNTS": "", "FIRST_EVENT_HEDGE": "auto", "FIRST_EVENT_HEDGE_MODELS": "gemini-4-argon",
}

Defaults 是 .env 全部配置项的默认值写法,与默认值相同的项不写入 .env

Functions

func FormatAPIKeyAccounts added in v0.1.7

func FormatAPIKeyAccounts(accounts map[string][]string) string

FormatAPIKeyAccounts 把 API key 绑定写成 .env 的取值,按 key 排序

func FormatModelMapping added in v0.1.3

func FormatModelMapping(mapping map[string]string) string

FormatModelMapping 按别名排序输出 MODEL_MAPPING 格式的映射

func MapModel

func MapModel(model string) string

MapModel 返回别名对应的真实模型标识

func ModelAliases added in v0.1.3

func ModelAliases() map[string]string

ModelAliases 返回当前模型别名映射的副本

func ParseAPIKeyAccounts added in v0.1.7

func ParseAPIKeyAccounts(value string, apiKeys string) (map[string][]string, error)

ParseAPIKeyAccounts 解析逗号分隔的“API key:账号|账号”绑定,跳过不在 apiKeys 中的 key,无效项与重复的 key 跳过并返回错误,其余绑定照常返回

func ParseModelMapping added in v0.1.3

func ParseModelMapping(value string) (map[string]string, error)

ParseModelMapping 解析逗号分隔的“别名:模型 ID”映射

func SetModelMapping

func SetModelMapping(mapping map[string]string)

SetModelMapping 替换当前模型别名映射

func SplitList added in v0.1.3

func SplitList(value string) []string

SplitList 按逗号拆分列表配置,去掉各项首尾空白与空项

func ValidateFirstEventHedge added in v0.1.7

func ValidateFirstEventHedge(value string) error

ValidateFirstEventHedge 检查首事件备用请求方式是 off、auto 或正整数秒

func WriteEnv added in v0.1.3

func WriteEnv(path string, values map[string]string) error

WriteEnv 把键值写入 .env:已有键原位替换,新键追加到末尾,与默认值相同的键删去,其余行与注释保持不变

Types

type Config

type Config struct {
	ListenAddress   string
	AuthStatePaths  []string
	ProxyAPIKey     string
	ProxyURL        string
	AccountCooldown time.Duration
	SessionTTL      time.Duration
	InitTimeout     time.Duration
	ModelMapping    map[string]string
	SaveHistory     bool
	LogLevel        string
	LogFormat       string
	RequestBodyLog  bool
	// LogFile 为 true 时日志同时写入数据目录的轮转文件,LogMaxTotalMB 是日志目录总量上限
	LogFile       bool
	LogMaxTotalMB int
	// PerAccountConcurrency 是每个账号同时进行的上游请求数
	PerAccountConcurrency int
	// RoutingStrategy 为 round-robin 或 fill-first
	RoutingStrategy string
	// AdminAuthEnabled 为 true 时管理端要求登录并接受远程访问
	AdminAuthEnabled bool
	AdminUsername    string
	AdminPassword    string
	// APIKeyAccounts 是各 API key 可用的账号 ID,未列出的 key 可用全部账号
	APIKeyAccounts map[string][]string
	// FirstEventHedge 是首事件备用请求方式:off、auto 或等待秒数
	FirstEventHedge string
	// FirstEventHedgeModels 是发起首事件备用请求的模型 ID
	FirstEventHedgeModels []string
	// Invalid 是加载时取值无效、改用默认值启动的配置项
	Invalid []InvalidValue
	// Locked 是由进程环境变量(env)或启动参数(flag)决定、设置页不能修改的配置项
	Locked map[string]string
}

Config 保存服务启动所需的全部配置

func Load

func Load() Config

Load 从环境变量读取配置,取值无效的项改用默认值并记入 Invalid

type InvalidValue added in v0.1.7

type InvalidValue struct {
	Key    string `json:"key"`
	Value  string `json:"value"`
	Reason string `json:"reason"`
}

InvalidValue 是加载时取值无效、改用默认值的配置项,含 API key 的 API_KEY_ACCOUNTS 不记 Value

Jump to

Keyboard shortcuts

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