config

package
v0.4.2 Latest Latest
Warning

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

Go to latest
Published: Jul 19, 2026 License: MIT Imports: 19 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DefaultDownloadPath     = "./downloads"
	DefaultFilenameTemplate = "{author} - {title}_{id}"
)
View Source
const DefaultConfigFileMode = constants.PrivateFileMode

Variables

This section is empty.

Functions

func ConfigFilePath

func ConfigFilePath() (string, error)

func EnvValue

func EnvValue(spec SettingSpec) (string, bool)

func NewLogger added in v0.2.0

func NewLogger(writer io.Writer, cfg RuntimeConfig) (*slog.Logger, error)

NewLogger 按已解析的运行时配置创建本进程根 logger。调用方决定输出流,CLI/MCP 一律传 stderr;本函数绝不设置或读取 slog 默认全局 logger。

func RefreshTokenFromEnv

func RefreshTokenFromEnv() (string, error)

RefreshTokenFromEnv 读取 App API refresh token。Cookie 形态在此处即被拒绝, 不能继续流入默认 SDK 的 OAuth 请求。

func SetConfigValue

func SetConfigValue(path, alias string, value parser.Value) error

func SetFilePathForTest

func SetFilePathForTest(configPath string) func()

func UnsetConfigValue

func UnsetConfigValue(path, alias string) (bool, error)

func ValidSettingAliases

func ValidSettingAliases() []string

func WritePrivateFile

func WritePrivateFile(path string, body []byte) error

Types

type RuntimeConfig

type RuntimeConfig struct {
	DownloadPath       string
	FilenameTemplate   string
	HTTPSProxy         string
	WebFallbackEnabled bool
	UpdateCheckEnabled bool
	OutputJSON         bool
	LoginOpenBrowser   bool
	LoginTimeout       time.Duration
	LoginUseAfterLogin bool
	// LogLevel 与 LogFormat 只描述应用根 logger,不会改变 slog 默认全局 logger。
	LogLevel  string
	LogFormat string
}

type SettingSpec

type SettingSpec struct {
	Alias      string
	KoanfKey   string
	Table      []string
	Key        string
	Kind       settingKind
	HasDefault bool
	Default    any
}

func SettingSpecByAlias

func SettingSpecByAlias(alias string) (SettingSpec, bool)

type SettingValue

type SettingValue struct {
	Value    any
	Text     string
	Source   string
	HasValue bool
}

func ParseSettingInput

func ParseSettingInput(alias, raw string) (SettingValue, parser.Value, error)

type SettingsState

type SettingsState struct {
	// contains filtered or unexported fields
}

func LoadSettingsState

func LoadSettingsState() (SettingsState, error)

func LoadSettingsStateAt added in v0.2.0

func LoadSettingsStateAt(path string) (SettingsState, error)

LoadSettingsStateAt 从明确给定的路径加载配置。SDK 需要它避免改动 包级测试路径或依赖调用进程的隐式当前配置位置。

func (SettingsState) Effective

func (s SettingsState) Effective(alias string) (SettingValue, error)

func (SettingsState) Runtime

func (s SettingsState) Runtime() (RuntimeConfig, error)

Jump to

Keyboard shortcuts

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