Documentation
¶
Overview ¶
Package settings 管理 config.toml 的 schema 与优先级解析。
Index ¶
- Constants
- Variables
- func ExpandEnvValue(value string, getenv func(string) string) (string, error)
- func NormalizeHost(host string) (string, error)
- func ResolveProxy(file Settings, flagProxy string) (string, error)
- func SaveFile(path string, s Settings) error
- func ValidateHost(host string) error
- type Document
- type ResolvedReverseSearch
- type ReverseSearchSettings
- type ReverseSearchSource
- type Runtime
- type Settings
Constants ¶
const ( DefaultReverseSearchSource = "builtin" DefaultReverseSearchCacheTTL = "720h" DefaultReverseSearchRetries = 3 DefaultReverseSearchRetryWait = "30s" DefaultReverseSearchRequestTimeout = "60s" )
reverse_search 区域默认值;超时/重试沿用参考服务行为且可配置。
const ( HostAuto = "auto" HostMirror = "mirror" HostMain = "main" )
Host names accepted by --host / config.
Variables ¶
var HostURLs = map[string]string{ HostMirror: "https://jdforrepam.com", HostMain: "https://javdb.com", }
HostURLs maps logical host names to base URLs.
Functions ¶
func ExpandEnvValue ¶ added in v0.7.0
ExpandEnvValue 展开 header 值中的 ${ENV:NAME} 引用。缺失或空的环境变量 报错只包含变量名,绝不包含展开后的值。
func NormalizeHost ¶
NormalizeHost 校验并规范逻辑 host 或绝对 HTTP(S) URL。绝对 URL 必须不含 query 或 fragment,否则 transport 以字符串拼接追加 API path 时会把 endpoint 拼进 query 或根本不 发给服务器。
func ResolveProxy ¶
ResolveProxy 按 flag > env > file 的优先级解析代理,供无需 JavDB host 的独立流程复用。
func SaveFile ¶
SaveFile writes settings sparsely to path (0600). 保存采用结构化合并:先读 既有配置树,只覆盖已知顶层键,未修改的表、source 数组与未知键保持原样。
func ValidateHost ¶
ValidateHost returns error if host is not a known name or absolute URL.
Types ¶
type Document ¶ added in v0.7.0
type Document struct {
// contains filtered or unexported fields
}
Document 是 config.toml 的结构化树视图:保存时保留未修改的表、source 数组 与未知键的语义值,不再整体重编码 typed struct。
func LoadDocument ¶ added in v0.7.0
LoadDocument 读取配置树;文件缺失返回空文档。
type ResolvedReverseSearch ¶ added in v0.7.0
type ResolvedReverseSearch struct {
DefaultSource string
Cache bool
CacheTTL time.Duration
Retries int
RetryWait time.Duration
RequestTimeout time.Duration
Sources []ReverseSearchSource
}
ResolvedReverseSearch 是校验并展开后的反搜配置;Headers 已完成环境展开。
func ResolveReverseSearch ¶ added in v0.7.0
func ResolveReverseSearch(s Settings, getenv func(string) string) (ResolvedReverseSearch, error)
ResolveReverseSearch 校验 reverse_search 区域并展开 header 环境引用。
type ReverseSearchSettings ¶ added in v0.7.0
type ReverseSearchSettings struct {
DefaultSource string `toml:"default_source"`
Cache *bool `toml:"cache"`
CacheTTL string `toml:"cache_ttl"`
Retries int `toml:"retries"`
RetryWait string `toml:"retry_wait"`
RequestTimeout string `toml:"request_timeout"`
Sources []ReverseSearchSource `toml:"sources"`
}
ReverseSearchSettings 是 [reverse_search] 表的 typed 视图。
func (ReverseSearchSettings) CacheEnabled ¶ added in v0.7.0
func (r ReverseSearchSettings) CacheEnabled() bool
CacheEnabled 报告反搜文件缓存是否启用(默认 true)。
type ReverseSearchSource ¶ added in v0.7.0
type ReverseSearchSource struct {
Name string `toml:"name"`
URL string `toml:"url"`
Headers map[string]string `toml:"headers"`
}
ReverseSearchSource 是 config.toml 中 [[reverse_search.sources]] 的一项。 Headers 的值只允许静态文本与 ${ENV:NAME} 引用,禁止明文 secret。
type Runtime ¶
type Runtime struct {
Host string // auto | mirror | main | URL
BaseURL string
Proxy string
AutoRelogin bool
Lang string
DeviceUUID string
}
Runtime is the resolved config after flag > env > file > default.
type Settings ¶
type Settings struct {
Host string `toml:"host"`
HTTPSProxy string `toml:"https_proxy,omitempty"`
AutoRelogin bool `toml:"auto_relogin"`
Lang string `toml:"lang,omitempty"`
DeviceUUID string `toml:"device_uuid,omitempty"` // optional override; else file/device_uuid
ReverseSearch ReverseSearchSettings `toml:"reverse_search"`
}
Settings is the on-disk config.toml schema.