Documentation
¶
Index ¶
- Variables
- func CLISettingAliases() []string
- func ClearFanboxDefaultUserID() error
- func ClearPixivDefaultUserID() error
- func EnsureDefaultConfigFile() error
- func EnvValue(spec SettingSpec) (string, bool)
- func IsSensitiveSetting(alias string) bool
- func PublicSettingText(alias, text string) string
- func ReadFanboxDefaultUserID() (userID int64, ok bool, err error)
- func ReadPixivDefaultUserID() (userID int64, ok bool, err error)
- func RemovedSettingError(alias string) error
- func SetConfigValue(path, alias string, value parser.Value) error
- func SetConfigValueWithFileStore(path, alias string, value parser.Value, store FileStore) error
- func SetFanboxDefaultUserID(userID int64) error
- func SetPixivDefaultUserID(userID int64) error
- func UnsetConfigValue(path, alias string) (bool, error)
- func UnsetConfigValueWithFileStore(path, alias string, store FileStore) (bool, error)
- func ValidSettingAliases() []string
- type AccountPoolConfig
- type AccountPoolStrategy
- type ConfigMutationResult
- type FileStore
- type FlareSolverrConfig
- type OptionalString
- type PixivNetworkConfig
- type RuntimeConfig
- type ServiceNetworkConfig
- type SettingSpec
- type SettingValue
- type Snapshot
- type Store
- func (s Store) ClearFanboxDefaultUserID() error
- func (s Store) ClearPixivDefaultUserID() error
- func (s Store) Current() (Snapshot, error)
- func (s Store) EnsureDefaultConfigFile() error
- func (s Store) Get(alias string) (SettingValue, error)
- func (s Store) Path() (string, error)
- func (s Store) ReadFanboxDefaultUserID() (userID int64, ok bool, err error)
- func (s Store) ReadPixivDefaultUserID() (userID int64, ok bool, err error)
- func (s Store) Set(alias, raw string) (ConfigMutationResult, error)
- func (s Store) SetFanboxDefaultUserID(userID int64) error
- func (s Store) SetPixivDefaultUserID(userID int64) error
- func (s Store) Unset(alias string) (ConfigMutationResult, error)
Constants ¶
This section is empty.
Variables ¶
var ErrRemovedSetting = errors.New("removed_setting")
ErrRemovedSetting 表示该配置键已随版本删除。旧配置仍显式包含它时返回;用户 通过 `pixiv config unset` 清理后不再出现。
Functions ¶
func CLISettingAliases ¶
func CLISettingAliases() []string
CLISettingAliases 返回由 pixiv config 命令管理的非移除配置键。
func ClearFanboxDefaultUserID ¶
func ClearFanboxDefaultUserID() error
ClearFanboxDefaultUserID 删除 [fanbox.auth].default_user_id,恢复首个入库账号。
func ClearPixivDefaultUserID ¶
func ClearPixivDefaultUserID() error
ClearPixivDefaultUserID 删除 [pixiv.auth].default_user_id,恢复首个入库账号。
func EnsureDefaultConfigFile ¶
func EnsureDefaultConfigFile() error
EnsureDefaultConfigFile 在配置首次缺失时生成由 schema 元数据驱动的精简基线文件。 高级设置仍需由用户显式写入,已有文件绝不覆盖。
func EnvValue ¶
func EnvValue(spec SettingSpec) (string, bool)
EnvValue 返回 spec 对应别名按 env 标签声明顺序解析到的环境变量值。
契约:
- 顺序即优先级,返回第一个**存在**的变量;某个变量存在但为空也算命中, 绝不继续回退到后续变量(这是服务级代理"显式直连"语义依赖的行为)。
- 未声明 env 标签的别名返回 ("", false)。
来源完全来自字段标签,不再维护独立的 alias switch。
func IsSensitiveSetting ¶
IsSensitiveSetting 标记禁止通过公开配置查询回显的凭据型值。
func PublicSettingText ¶
PublicSettingText 返回可安全进入 CLI、SDK JSON 与日志边界的配置值。
func ReadFanboxDefaultUserID ¶
ReadFanboxDefaultUserID 返回 [fanbox.auth].default_user_id;未设置时 ok=false。
func ReadPixivDefaultUserID ¶
ReadPixivDefaultUserID 返回 [pixiv.auth].default_user_id;未设置时 ok=false。
func RemovedSettingError ¶
RemovedSettingError 构造一个同时能被 errors.Is 匹配 ErrRemovedSetting 的错误, 明确指导用户如何清理旧配置。已移除键在显式写入配置时对 runtime 生效,不设置 默认值,也不进入可写别名集合。
func SetConfigValueWithFileStore ¶
SetConfigValueWithFileStore 在注入的文件端口上执行稀疏配置写回。
func SetFanboxDefaultUserID ¶
SetFanboxDefaultUserID 写入 [fanbox.auth].default_user_id。
func SetPixivDefaultUserID ¶
SetPixivDefaultUserID 写入 [pixiv.auth].default_user_id。
func UnsetConfigValue ¶
func UnsetConfigValueWithFileStore ¶
UnsetConfigValueWithFileStore 在注入的文件端口上删除一个配置键。
func ValidSettingAliases ¶
func ValidSettingAliases() []string
Types ¶
type AccountPoolConfig ¶
type AccountPoolConfig struct {
Enabled bool `config:"enabled" alias:"account_pool_enabled" default:"false" cli:"true"`
Strategy AccountPoolStrategy `config:"strategy" alias:"account_pool_strategy" default:"round_robin" cli:"true"`
}
AccountPoolConfig 描述内容读取和作品下载是否启用数据库账号调度及其策略。 UID、冻结时间和 marker 不进入 config.toml。字段标签驱动声明;[account_pool] 表仍直接读取,策略枚举由 accountPool() 的领域校验负责。
type AccountPoolStrategy ¶
type AccountPoolStrategy string
const ( AccountPoolStrategyRoundRobin AccountPoolStrategy = "round_robin" AccountPoolStrategyRandom AccountPoolStrategy = "random" )
type ConfigMutationResult ¶
type FileStore ¶
type FileStore interface {
Path() (string, error)
ReadFile(string) ([]byte, error)
WritePrivateFile(string, []byte) error
EnsurePrivateFile(string, []byte) error
}
FileStore 是 config/settings 所需的最小文件端口。生产实现由 composition root 注入;配置 schema 不直接依赖具体文件系统实现。
type FlareSolverrConfig ¶
type FlareSolverrConfig struct {
URL string `config:"url" json:"url"`
ProxyURL string `config:"proxy_url" json:"proxy_url,omitempty"`
}
FlareSolverrConfig describes the optional external challenge-recovery service. It is nil when the whole table is absent, which keeps the default runtime free of any solver dependency.
type OptionalString ¶
OptionalString preserves the difference between an absent advanced TOML key and an explicitly configured empty string. That distinction is required for service-scoped proxy routing: an empty service value means direct access instead of inheriting the global fallback.
type PixivNetworkConfig ¶ added in v1.2.0
type PixivNetworkConfig struct {
ProxyURL OptionalString `config:"proxy_url" json:"proxy_url"`
}
PixivNetworkConfig 是 Pixiv 服务级网络的**窄类型**:它只有 proxy_url。
Pixiv 与 FANBOX/反搜的网络字段并不相同:Pixiv 不接受服务级 user_agent。之前用 共享结构体 + `includeUserAgent` 程序分支来维持这个差异,容易在重构中被误删。 用独立类型表达后,`pixiv.network.user_agent` 在类型层面就无法表达,也无法被绑定, 因此不会在重构中意外变成新的用户可配置能力。
type RuntimeConfig ¶
type RuntimeConfig struct {
MCPGalleryAnimationTempCapacityMiB int64 `config:"mcp.gallery_animation_temp_capacity_mib" alias:"mcp_gallery_animation_temp_capacity_mib" default:"1024" cli:"true"`
MCPGalleryCacheCapacityMiB int64 `config:"mcp.gallery_cache_capacity_mib" alias:"mcp_gallery_cache_capacity_mib" default:"256" cli:"true"`
MCPGalleryCacheTTL time.Duration `config:"mcp.gallery_cache_ttl" alias:"mcp_gallery_cache_ttl" default:"15m" cli:"true"`
MCPGalleryConcurrency int `config:"mcp.gallery_concurrency" alias:"mcp_gallery_concurrency" default:"4" cli:"true"`
// DownloadPath 是作品下载根目录;未配置时使用相对当前工作目录的路径。
DownloadPath string `config:"download.path" alias:"download_path" env:"DOWNLOAD_PATH" default:"./downloads" cli:"true" example:"true"`
// FilenameTemplate 是下载文件名模板,进入首次生成的精简配置。
FilenameTemplate string `` /* 145-byte string literal not displayed */
// DirectoryTemplate 是可选下载子目录模板;没有默认值,因此不进入精简配置。
DirectoryTemplate string `config:"download.directory_template" alias:"directory_template" env:"DIRECTORY_TEMPLATE" cli:"true"`
// HTTPSProxy 保留小写环境变量优先于大写环境变量的现有顺序,且没有默认值。
HTTPSProxy string `config:"network.https_proxy" alias:"https_proxy" env:"https_proxy,HTTPS_PROXY" cli:"true"`
// RequestInterval 具有运行时默认值,但不写入精简初始文件。
RequestInterval time.Duration `config:"network.request_interval" alias:"request_interval" env:"PIXIV_REQUEST_INTERVAL" default:"0s" cli:"true"`
// LogLevel 与 LogFormat 具有默认值并进入精简配置。
LogLevel string `config:"logging.level" alias:"log_level" env:"PIXIV_LOG_LEVEL" default:"info" cli:"true" example:"true"`
LogFormat string `config:"logging.format" alias:"log_format" env:"PIXIV_LOG_FORMAT" default:"text" cli:"true" example:"true"`
// PixivNetwork / FanboxNetwork / ReverseSearchNetwork 以及两个 FlareSolverr 组
// 是高级可选配置,只在用户显式写入 TOML 表时生效,且不经过扁平 config set。
// 路径来自声明;存在性、严格类型和 solver 启用条件仍由 snapshot.go 领域读取负责。
PixivNetwork PixivNetworkConfig `config:"pixiv.network"`
FanboxNetwork ServiceNetworkConfig `config:"fanbox.network"`
ReverseSearchNetwork ServiceNetworkConfig `config:"reverse_search.network"`
FanboxFlareSolverr *FlareSolverrConfig `config:"fanbox.flaresolverr"`
ReverseSearchFlareSolverr *FlareSolverrConfig `config:"reverse_search.flaresolverr"`
// 布尔开关:除 account_pool 外都不由 config 命令管理。
OutputJSON bool `config:"output.json" alias:"output_json" default:"false" example:"true"`
UpdateCheckEnabled bool `config:"update.check_enabled" alias:"update_check_enabled" default:"true" example:"true"`
LoginOpenBrowser bool `config:"login.open_browser" alias:"login_open_browser" default:"true" example:"true"`
LoginUseAfterLogin bool `config:"login.use_after_login" alias:"login_use_after_login" default:"false" example:"true"`
// 反搜设置。SauceNAOAPIKey 只能经过现有私密输入链路写入,不进入初始配置或公开输出。
ReverseSearchProvider string `config:"reverse_search.provider" alias:"reverse_search_provider" default:"saucenao" cli:"true" example:"true"`
ReverseSearchPixivOnly bool `config:"reverse_search.pixiv_only" alias:"reverse_search_pixiv_only" default:"true" cli:"true" example:"true"`
SauceNAOAPIKey string `config:"reverse_search.saucenao_api_key" alias:"saucenao_api_key" env:"SAUCENAO_API_KEY" cli:"true" secret:"true"`
// LoginRelay* 描述本次运行时创建的跨机器浏览器中继。历史 secret/target
// 配置项仍可留在私有配置文件中,但不会载入 runtime,避免恢复旧 client relay。
LoginRelayPublicURL string `config:"login.relay_public_url" alias:"login_relay_public_url"`
LoginRelayListenAddr string `config:"login.relay_listen_addr" alias:"login_relay_listen_addr"`
LoginRelayTLSCertFile string `config:"login.relay_tls_cert_file" alias:"login_relay_tls_cert_file"`
LoginRelayTLSKeyFile string `config:"login.relay_tls_key_file" alias:"login_relay_tls_key_file"`
// AccountPool 的静态路径来自组前缀;严格类型和策略校验仍由领域读取负责。
AccountPool AccountPoolConfig `config:"account_pool"`
}
type ServiceNetworkConfig ¶
type ServiceNetworkConfig struct {
ProxyURL OptionalString `config:"proxy_url" json:"proxy_url"`
UserAgent OptionalString `config:"user_agent" json:"user_agent"`
}
ServiceNetworkConfig contains only service-local network settings. These values are not aliases and are intentionally absent from the generated baseline config until a user writes the advanced TOML table.
type SettingSpec ¶
type SettingSpec struct {
Alias string
KoanfKey string
Table []string
Key string
Kind settingKind
// Sensitive 表示该值可用于认证或中继授权。它可以被写入私有 config.toml,
// 但绝不能通过 config get、日志或错误消息回显。
Sensitive bool
HasDefault bool
Default any
// DefaultInFile 表示该默认值是否进入首次生成的精简 config.toml。
DefaultInFile bool
// CLIManaged 表示该键是否由 pixiv config get/set/unset 暴露。
CLIManaged bool
// Removed 表示该键已随版本删除,只保留迁移墓碑。旧配置仍显式包含它时返回
// removed_setting;pixiv config unset 允许用户清理。墓碑不得驱动运行时分支。
Removed bool
}
func SettingSpecByAlias ¶
func SettingSpecByAlias(alias string) (SettingSpec, bool)
SettingSpecByAlias 返回 alias 对应的 spec。已移除键仍可被查询,以便 config unset 执行清理、config get/set 返回 removed_setting。元数据完全来自字段标签声明。 Table 返回独立副本,调用方修改不会污染静态声明。
type SettingValue ¶
func ParseSettingInput ¶
func ParseSettingInput(alias, raw string) (SettingValue, parser.Value, error)
type Snapshot ¶
type Snapshot struct {
// contains filtered or unexported fields
}
func LoadSnapshot ¶
func LoadSnapshotAt ¶
LoadSnapshotAt 从明确给定的路径加载配置。SDK 需要它避免改动 包级测试路径或依赖调用进程的隐式当前配置位置。
func LoadSnapshotAtWithFileStore ¶
LoadSnapshotAtWithFileStore 从明确路径和注入的文件端口加载配置。它 让 composition root 可以把 platform/file mechanism 适配传入 schema owner。 LoadSnapshotAtWithFileStore 从明确路径与注入的文件端口生成一次不可变快照。
配置绑定整体分四个阶段,本函数只负责**阶段 1**:
- 固定本次读取的文件与环境视图,避免同一个快照内出现不同结果;
- 按**存在性**选择来源(见 Effective);
- 按既有输入契约解析类型并执行领域校验(见 coerceSettingValue 与 Runtime 中的领域规则);
- 返回类型化配置;读取过程**不回写**用户文件(写回只属 document.go)。
阶段 1 的具体含义:文件内容在此一次性装入 koanf,环境变量在此一次性捕获; 之后无论 Effective 被调用多少次,同一快照都看到同一份输入。
func (Snapshot) Effective ¶
func (s Snapshot) Effective(alias string) (SettingValue, error)
Effective 解析单个配置别名的最终值,返回该值及其来源。
契约:
- 来源优先级固定为 env → file → default;返回的 Source 就是实际选中的那一层。
- 选择依据是**存在性**,不是"值是否非零":显式配置的空字符串、false、0s 都与"缺失"区分开,并且一旦某层命中就不再回退到更低优先级。
- 全部未命中时返回 Source="unset"、HasValue=false,调用方据此区分 "没有配置"与"配置成了零值"。
- 退役键(spec.Removed)仅在**显式出现**于文件时报 removed_setting;缺失时静默 返回 unset,因此 config unset 仍能清理它。
这是绑定四阶段中的**阶段 2**(按存在性选择来源);类型解析与领域校验由 coerceSettingValue(阶段 3)负责,本函数不回写任何文件(阶段 4)。
func (Snapshot) Runtime ¶
func (s Snapshot) Runtime() (RuntimeConfig, error)
type Store ¶
type Store struct {
Files FileStore
}
Store 是配置 schema、文件 precedence 与稀疏写回的唯一 authority。 Files 只提供协议无关的路径/文件机制;Store 不缓存读取结果。
func DefaultStore ¶
func DefaultStore() Store
DefaultStore 返回使用 config/paths 默认路径与私密文件机制的配置 store。 需要注入文件端口的测试或 CLI composition root 应直接构造 Store{Files: ...}。
func (Store) ClearFanboxDefaultUserID ¶
func (Store) ClearPixivDefaultUserID ¶
func (Store) Current ¶
Current 每次从当前文件与环境生成新的 Snapshot。调用方应在一次 command/tool execution 开始时获取一次,并把该不可变快照传给后续依赖,避免运行中途配置撕裂。
func (Store) EnsureDefaultConfigFile ¶
EnsureDefaultConfigFile 在首次缺失时创建基线配置,且使用注入端口提供的 私密文件语义;已有文件不会被覆盖。
func (Store) ReadFanboxDefaultUserID ¶
func (Store) ReadPixivDefaultUserID ¶
ReadPixivDefaultUserID 从注入的配置文件端口读取默认账号 UID。
func (Store) SetFanboxDefaultUserID ¶
func (Store) SetPixivDefaultUserID ¶
SetPixivDefaultUserID 写入注入的配置文件端口。