settings

package
v0.8.3 Latest Latest
Warning

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

Go to latest
Published: Oct 22, 2026 License: MIT Imports: 11 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 settings 管理 config.toml 的 schema 与优先级解析。

Index

Constants

View Source
const (
	DefaultReverseSearchSource         = "builtin"
	DefaultReverseSearchCacheTTL       = "720h"
	DefaultReverseSearchRetries        = 3
	DefaultReverseSearchRetryWait      = "30s"
	DefaultReverseSearchRequestTimeout = "60s"
)

reverse_search 区域默认值;超时/重试沿用参考服务行为且可配置。

View Source
const (
	HostAuto   = "auto"
	HostMirror = "mirror"
	HostMain   = "main"
)

Host names accepted by --host / config.

View Source
const DefaultAssetProbeConcurrency = 4

Variables

View Source
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

func ExpandEnvValue(value string, getenv func(string) string) (string, error)

ExpandEnvValue 展开 header 值中的 ${ENV:NAME} 引用。缺失或空的环境变量 报错只包含变量名,绝不包含展开后的值。

func NormalizeHost

func NormalizeHost(host string) (string, error)

NormalizeHost 校验并规范逻辑 host 或绝对 HTTP(S) URL。绝对 URL 必须不含 query 或 fragment,否则 transport 以字符串拼接追加 API path 时会把 endpoint 拼进 query 或根本不 发给服务器。

func ResolveProxy

func ResolveProxy(file Settings, flagProxy string) (string, error)

ResolveProxy 按 flag > env > file 的优先级解析代理,供无需 JavDB host 的独立流程复用。

func SaveFile

func SaveFile(path string, s Settings) error

SaveFile writes settings sparsely to path (0600). 保存采用结构化合并:先读 既有配置树,只覆盖已知顶层键,未修改的表、source 数组与未知键保持原样。

func ValidateHost

func ValidateHost(host string) error

ValidateHost returns error if host is not a known name or absolute URL.

Types

type AssetProbeSettings added in v0.8.0

type AssetProbeSettings struct {
	Enabled     *bool `toml:"enabled"`
	Concurrency *int  `toml:"concurrency"`
}

AssetProbeSettings 是 config.toml 中可选的 [assets.probe] 配置。

type AssetsSettings added in v0.8.0

type AssetsSettings struct {
	Probe AssetProbeSettings `toml:"probe"`
}

AssetsSettings 是 assets 配置表。

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

func LoadDocument(path string) (*Document, error)

LoadDocument 读取配置树;文件缺失返回空文档。

func (*Document) Delete added in v0.7.0

func (d *Document) Delete(key string) error

Delete 通过点路径删除键;键不存在是 no-op。

func (*Document) Save added in v0.7.0

func (d *Document) Save(path string) error

Save 把整棵树以原子方式写回 path(0600)。

func (*Document) Set added in v0.7.0

func (d *Document) Set(key string, value any) error

Set 通过点路径写入标量值,必要时创建中间表。

type ResolvedAssetProbe added in v0.8.0

type ResolvedAssetProbe struct {
	Enabled     bool
	Concurrency int
}

ResolvedAssetProbe 是应用默认值并通过校验后的 probe 配置。

func ResolveAssetProbe added in v0.8.0

func ResolveAssetProbe(s Settings) (ResolvedAssetProbe, error)

ResolveAssetProbe 返回当前有效的资产探测配置。

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.

func Resolve

func Resolve(file Settings, flagHost, flagProxy string, flagAutoRelogin *bool) (Runtime, error)

Resolve merges flag/env/file/defaults. flagHost / flagProxy empty means "not set". flagAutoRelogin: nil = not set; non-nil overrides.

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"`
	Assets        AssetsSettings        `toml:"assets"`
}

Settings is the on-disk config.toml schema.

func Defaults

func Defaults() Settings

Defaults returns baseline settings.

func LoadFile

func LoadFile(path string) (Settings, error)

LoadFile reads config.toml; missing file returns Defaults().

Jump to

Keyboard shortcuts

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