config

package
v1.4.0 Latest Latest
Warning

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

Go to latest
Published: Nov 21, 2026 License: MIT Imports: 18 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 config 读取本机配置、环境变量,并负责保留注释的 TOML 写回。

Config 保存一次读取的有效值,Default 提供默认值;Store 通过文件端口读写配置。

Index

Constants

View Source
const (
	VectorModelKey  = "vector.model"
	VectorDeviceKey = "vector.device"
	VectorAPIKey    = "vector.api_key"
	VectorBaseURL   = "vector.base_url"
)

VectorModelKey、VectorDeviceKey、VectorAPIKey 与 VectorBaseURL 是公开 TOML 路径。

View Source
const (
	// AppDataDirName 指定本项目所有本机持久状态的唯一根目录名。
	AppDataDirName = ".pixiv-cli"
	// PrivateDirMode 指定私有目录的权限位。
	PrivateDirMode = 0o700
	// PrivateFileMode 指定私有文件的权限位。
	PrivateFileMode = 0o600
)

Variables

This section is empty.

Functions

func AppDataDir added in v1.4.0

func AppDataDir() (string, error)

AppDataDir 返回本项目当前用户的私有应用数据根目录。

func ConfigFilePath

func ConfigFilePath() (string, error)

ConfigFilePath 返回 config.toml 的应用管理路径。

func EnvironmentOverride added in v1.4.0

func EnvironmentOverride(key string) bool

EnvironmentOverride 报告目标键是否受环境变量覆盖。

func HTTPClient added in v1.4.0

func HTTPClient(proxyValue string) (*http.Client, error)

HTTPClient 根据代理配置创建独立的 HTTP transport;空值表示直连。

func Keys added in v1.4.0

func Keys() []string

Keys 列出 config get/set/unset 接受的 TOML 叶子路径。

func UserDataFile added in v1.4.0

func UserDataFile(appName, filename string) (string, error)

UserDataFile 返回应用数据目录内的指定文件路径。

func UserDataSubdir added in v1.4.0

func UserDataSubdir(appName string) (string, error)

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 分节保存配置;可选指针区分缺失与显式空值。

func Default added in v1.4.0

func Default() Config

Default 返回独立的默认配置。

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

type FlareSolverrConfig struct {
	URL      *string `toml:"url"`
	ProxyURL *string `toml:"proxy_url"`
}

FlareSolverrConfig 在任一字段出现时要求 URL 非空。

type LogFormat added in v1.4.0

type LogFormat string

LogFormat 枚举诊断输出格式配置的取值。

const (
	LogFormatText LogFormat = "text"
	LogFormatJSON LogFormat = "json"
)

LogFormatText 输出带来源位置的文本,LogFormatJSON 输出 JSON 对象。

type LogLevel added in v1.4.0

type LogLevel string

LogLevel 枚举日志级别配置的取值。

const (
	LogLevelInfo  LogLevel = "info"
	LogLevelDebug LogLevel = "debug"
	LogLevelWarn  LogLevel = "warn"
	LogLevelError LogLevel = "error"
)

LogLevelInfo、LogLevelDebug、LogLevelWarn 与 LogLevelError 是 Config 接受的全部值,也是命令行诊断输出的级别。

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

func (s Store) ClearFanboxDefaultUserID() error

ClearFanboxDefaultUserID 删除 FANBOX 默认账号选择。

func (Store) ClearPixivDefaultUserID added in v1.4.0

func (s Store) ClearPixivDefaultUserID() error

ClearPixivDefaultUserID 删除 Pixiv 默认账号选择。

func (Store) Current added in v1.4.0

func (s Store) Current() (Config, error)

Current 先应用默认值,再解码文件并按存在性覆盖环境变量;未知文件键被忽略。

func (Store) EnsureDefaultConfigFile added in v1.4.0

func (s Store) EnsureDefaultConfigFile() error

EnsureDefaultConfigFile 在文件缺失时原样写出带注释的模板。

func (Store) Get added in v1.4.0

func (s Store) Get(key string) (string, bool, error)

Get 返回目标键的有效值及存在性;向量服务 API key 仅返回脱敏值。

func (Store) Path added in v1.4.0

func (s Store) Path() (string, error)

Path 返回配置文件路径。

func (Store) ReadFanboxDefaultUserID added in v1.4.0

func (s Store) ReadFanboxDefaultUserID() (int64, bool, error)

ReadFanboxDefaultUserID 只读取 FANBOX 默认账号,缺失时 ok 为 false。

func (Store) ReadPixivDefaultUserID added in v1.4.0

func (s Store) ReadPixivDefaultUserID() (int64, bool, error)

ReadPixivDefaultUserID 只读取 Pixiv 默认账号,缺失时 ok 为 false。

func (Store) Set added in v1.4.0

func (s Store) Set(key, raw string) error

Set 按目标字段类型和取值规则校验输入,保留目标键注释与其他键。

func (Store) SetFanboxDefaultUserID added in v1.4.0

func (s Store) SetFanboxDefaultUserID(id int64) error

SetFanboxDefaultUserID 写入正整数 UID,保留其他配置。

func (Store) SetPixivDefaultUserID added in v1.4.0

func (s Store) SetPixivDefaultUserID(id int64) error

SetPixivDefaultUserID 写入正整数 UID,保留其他配置。

func (Store) Unset added in v1.4.0

func (s Store) Unset(key string) error

Unset 删除目标 TOML 叶子路径,其他键保持原样。

func (Store) WriteVector added in v1.4.0

func (s Store) WriteVector(value *Vector) error

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 为空时关闭记录和搜索。

func (Vector) Format added in v1.4.0

func (v Vector) Format(state fmt.State, _ rune)

Format 在诊断输出中隐藏云端 API key。

type VectorDevice added in v1.4.0

type VectorDevice string

VectorDevice 选择本地图片推理设备;空值与 CPU 相同。

const (
	VectorCPU VectorDevice = "cpu"
	VectorGPU VectorDevice = "gpu"
)

VectorCPU 与 VectorGPU 是显式设备选项。

Jump to

Keyboard shortcuts

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