settings

package
v0.6.0 Latest Latest
Warning

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

Go to latest
Published: Aug 12, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package settings 管理 config.toml 的 schema 与优先级解析。

Index

Constants

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

Host names accepted by --host / config.

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 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).

func ValidateHost

func ValidateHost(host string) error

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

Types

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
}

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