Documentation
¶
Overview ¶
Package config 读取本机配置、环境变量,并负责保留注释的 TOML 写回。
Index ¶
- Constants
- func AppDataDir() (string, error)
- func ConfigFilePath() (string, error)
- func EnvironmentOverride(key string) bool
- func HTTPClient(proxyValue string) (*http.Client, error)
- func Keys() []string
- func UserDataFile(appName, filename string) (string, error)
- func UserDataSubdir(appName string) (string, error)
- type AccountPoolConfig
- type AccountPoolStrategy
- type Config
- type FileStore
- type FlareSolverrConfig
- type LogFormat
- type LogLevel
- type ServiceNetworkConfig
- type Store
- func (s Store) ClearFanboxDefaultUserID() error
- func (s Store) ClearPixivDefaultUserID() error
- func (s Store) Current() (Config, error)
- func (s Store) EnsureDefaultConfigFile() error
- func (s Store) Get(key string) (string, bool, error)
- func (s Store) Path() (string, error)
- func (s Store) ReadFanboxDefaultUserID() (int64, bool, error)
- func (s Store) ReadPixivDefaultUserID() (int64, bool, error)
- func (s Store) Set(key, raw string) error
- func (s Store) SetFanboxDefaultUserID(id int64) error
- func (s Store) SetPixivDefaultUserID(id int64) error
- func (s Store) Unset(key string) error
- func (s Store) WriteVector(value *Vector) error
- type Vector
- type VectorDevice
Constants ¶
const ( VectorModelKey = "vector.model" VectorDeviceKey = "vector.device" VectorAPIKey = "vector.api_key" VectorBaseURL = "vector.base_url" )
VectorModelKey、VectorDeviceKey、VectorAPIKey 与 VectorBaseURL 是公开 TOML 路径。
const ( // AppDataDirName 指定本项目所有本机持久状态的唯一根目录名。 AppDataDirName = ".pixiv-cli" // PrivateDirMode 指定私有目录的权限位。 PrivateDirMode = 0o700 // PrivateFileMode 指定私有文件的权限位。 PrivateFileMode = 0o600 )
Variables ¶
This section is empty.
Functions ¶
func EnvironmentOverride ¶ added in v1.4.0
EnvironmentOverride 报告目标键是否受环境变量覆盖。
func HTTPClient ¶ added in v1.4.0
HTTPClient 根据代理配置创建独立的 HTTP transport;空值表示直连。
func UserDataFile ¶ added in v1.4.0
UserDataFile 返回应用数据目录内的指定文件路径。
func UserDataSubdir ¶ added in v1.4.0
UserDataSubdir 返回当前用户 home 下的应用数据目录。所有平台均使用相同的 `~/APP_NAME` 语义;Windows 上的 home 由 os.UserHomeDir 解析为用户 profile。
Types ¶
type AccountPoolConfig ¶ added in v0.8.0
type AccountPoolConfig struct {
Enabled bool `toml:"enabled"`
Strategy AccountPoolStrategy `toml:"strategy"`
}
AccountPoolConfig 描述内容读取和作品下载是否启用数据库账号调度及其策略。
UID、冻结时间和 marker 不进入 config.toml,策略枚举的有效性由领域读取负责。
type AccountPoolStrategy ¶ added in v0.8.0
type AccountPoolStrategy string
AccountPoolStrategy 选择账号池在多个可用账号之间的调度方式。
const ( AccountPoolStrategyRoundRobin AccountPoolStrategy = "round_robin" AccountPoolStrategyRandom AccountPoolStrategy = "random" )
AccountPoolStrategyRoundRobin 按 sort_order 轮转,AccountPoolStrategyRandom 随机选取。
type Config ¶ added in v1.4.0
type Config struct {
Vector Vector `toml:"vector"`
MCP struct {
GalleryAnimationTempCapacityMiB int64 `toml:"gallery_animation_temp_capacity_mib"`
GalleryCacheCapacityMiB int64 `toml:"gallery_cache_capacity_mib"`
} `toml:"mcp"`
Download struct {
Path string `toml:"path"`
FilenameTemplate string `toml:"filename_template"`
DirectoryTemplate string `toml:"directory_template"`
} `toml:"download"`
Network struct {
HTTPSProxy string `toml:"https_proxy"`
RequestInterval string `toml:"request_interval"` // Go duration 字符串,与已有文件一致。
} `toml:"network"`
Logging struct {
Level LogLevel `toml:"level"`
Format LogFormat `toml:"format"`
} `toml:"logging"`
Output struct {
JSON bool `toml:"json"`
} `toml:"output"`
Update struct {
CheckEnabled bool `toml:"check_enabled"`
} `toml:"update"`
Login struct {
OpenBrowser bool `toml:"open_browser"`
UseAfterLogin bool `toml:"use_after_login"`
RelayPublicURL string `toml:"relay_public_url"`
RelayListenAddr string `toml:"relay_listen_addr"`
RelayTLSCertFile string `toml:"relay_tls_cert_file"`
RelayTLSKeyFile string `toml:"relay_tls_key_file"`
} `toml:"login"`
Pixiv struct {
Network struct {
ProxyURL *string `toml:"proxy_url"`
} `toml:"network"`
Auth struct {
DefaultUserID *int64 `toml:"default_user_id"`
} `toml:"auth"`
} `toml:"pixiv"`
Fanbox struct {
Network ServiceNetworkConfig `toml:"network"`
FlareSolverr FlareSolverrConfig `toml:"flaresolverr"`
Auth struct {
DefaultUserID *int64 `toml:"default_user_id"`
} `toml:"auth"`
} `toml:"fanbox"`
ReverseSearch struct {
Provider string `toml:"provider"`
PixivOnly bool `toml:"pixiv_only"`
SauceNAOAPIKey string `toml:"saucenao_api_key"`
Network ServiceNetworkConfig `toml:"network"`
FlareSolverr FlareSolverrConfig `toml:"flaresolverr"`
} `toml:"reverse_search"`
AccountPool AccountPoolConfig `toml:"account_pool"`
}
Config 按 TOML 分节保存配置;可选指针区分缺失与显式空值。
type FileStore ¶ added in v1.4.0
type FileStore interface {
Path() (string, error)
ReadFile(string) ([]byte, error)
WritePrivateFile(string, []byte) error
EnsurePrivateFile(string, []byte) error
}
FileStore 把配置解析与文件权限、原子替换机制分开。
type FlareSolverrConfig ¶ added in v1.4.0
FlareSolverrConfig 在任一字段出现时要求 URL 非空。
type ServiceNetworkConfig ¶ added in v1.4.0
type ServiceNetworkConfig struct {
ProxyURL *string `toml:"proxy_url"`
UserAgent *string `toml:"user_agent"`
}
ServiceNetworkConfig 的空代理值表示直连,nil 表示沿用全局代理。
type Store ¶ added in v1.4.0
type Store struct{ Files FileStore }
Store 每次读取文件和环境变量,调用方在一次执行内复用返回的 Config。
func (Store) ClearFanboxDefaultUserID ¶ added in v1.4.0
ClearFanboxDefaultUserID 删除 FANBOX 默认账号选择。
func (Store) ClearPixivDefaultUserID ¶ added in v1.4.0
ClearPixivDefaultUserID 删除 Pixiv 默认账号选择。
func (Store) EnsureDefaultConfigFile ¶ added in v1.4.0
EnsureDefaultConfigFile 在文件缺失时原样写出带注释的模板。
func (Store) ReadFanboxDefaultUserID ¶ added in v1.4.0
ReadFanboxDefaultUserID 只读取 FANBOX 默认账号,缺失时 ok 为 false。
func (Store) ReadPixivDefaultUserID ¶ added in v1.4.0
ReadPixivDefaultUserID 只读取 Pixiv 默认账号,缺失时 ok 为 false。
func (Store) SetFanboxDefaultUserID ¶ added in v1.4.0
SetFanboxDefaultUserID 写入正整数 UID,保留其他配置。
func (Store) SetPixivDefaultUserID ¶ added in v1.4.0
SetPixivDefaultUserID 写入正整数 UID,保留其他配置。
func (Store) WriteVector ¶ added in v1.4.0
WriteVector 原子写入整组向量配置;nil 删除全部声明的向量键,其他配置和注释保留。
type Vector ¶ added in v1.4.0
type Vector struct {
Model string `toml:"model"`
Device VectorDevice `toml:"device"`
APIKey string `toml:"api_key" json:"-"`
BaseURL string `toml:"base_url"`
}
Vector 保存模型选择与云端鉴权;Model 为空时关闭记录和搜索。
type VectorDevice ¶ added in v1.4.0
type VectorDevice string
VectorDevice 选择本地图片推理设备;空值与 CPU 相同。
const ( VectorCPU VectorDevice = "cpu" VectorGPU VectorDevice = "gpu" )
VectorCPU 与 VectorGPU 是显式设备选项。