bootstrap

package
v1.11.0 Latest Latest
Warning

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

Go to latest
Published: Jul 16, 2026 License: GPL-3.0 Imports: 34 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AppDataDir

func AppDataDir() string

AppDataDir 返回应用数据目录。 便携模式(可执行文件同级存在 data 目录)优先,否则用平台默认目录。

func AuthTokenPath

func AuthTokenPath(dataDir string) string

AuthTokenPath 返回认证 token 文件路径

func GenerateAuthToken

func GenerateAuthToken(dataDir string) (string, error)

GenerateAuthToken 生成随机认证 token 并写入文件(0600 权限)

func GetLogsDir added in v1.4.0

func GetLogsDir() string

GetLogsDir 返回日志目录路径(Init 后用其实际数据目录,未初始化时回退默认目录)

func Init

func Init(ctx context.Context, opts Options) error

Init 初始化数据库、凭证服务、注册 Repository、运行迁移

func InitLogger added in v1.4.0

func InitLogger() error

InitLogger 根据当前 AppConfig.DebugMode 构建 zap logger 并设为全局实例。 Debug 模式下 opskat.log 记录 debug+;否则记录 info+。error.log 始终只收 error+。 运行时切换 Debug 开关可再次调用本函数热更新。

func ReadAuthToken

func ReadAuthToken(dataDir string) (string, error)

ReadAuthToken 从文件读取认证 token

func ResolvedDataDir added in v1.9.0

func ResolvedDataDir() string

ResolvedDataDir 返回 Init 实际使用的数据目录;Init 之前回退到默认平台目录。

func SaveConfig

func SaveConfig(cfg *AppConfig) error

SaveConfig 保存配置到文件

Types

type AppConfig

type AppConfig struct {
	UpdateChannel                   string `json:"update_channel,omitempty"`                    // stable, beta, nightly
	DownloadMirror                  string `json:"download_mirror,omitempty"`                   // 下载镜像 URL 前缀,空表示直连 GitHub
	KDFSalt                         string `json:"kdf_salt,omitempty"`                          // base64 编码的 Argon2id salt
	AIProviderType                  string `json:"ai_provider_type,omitempty"`                  // openai, local_cli
	AIAPIBase                       string `json:"ai_api_base,omitempty"`                       // API base URL 或 CLI 路径
	AIAPIKey                        string `json:"ai_api_key,omitempty"`                        // 加密后的 API Key
	AIModel                         string `json:"ai_model,omitempty"`                          // 模型名或 CLI 类型
	GitHubToken                     string `json:"github_token,omitempty"`                      // 加密后的 GitHub token
	GitHubUser                      string `json:"github_user,omitempty"`                       // GitHub 用户名(非敏感)
	WebDAVURL                       string `json:"webdav_url,omitempty"`                        // WebDAV 备份目录
	WebDAVAuthType                  string `json:"webdav_auth_type,omitempty"`                  // "none" | "basic" | "bearer"
	WebDAVUsername                  string `json:"webdav_username,omitempty"`                   // WebDAV 用户名(非敏感,仅 basic)
	WebDAVPassword                  string `json:"webdav_password,omitempty"`                   // 加密后的 WebDAV 密码(仅 basic)
	WebDAVToken                     string `json:"webdav_token,omitempty"`                      // 加密后的 Bearer token(仅 bearer)
	WebDAVExportDefaultsConfigured  bool   `json:"webdav_export_defaults_configured,omitempty"` // 是否已保存 WebDAV 导出默认项
	WebDAVExportPassword            string `json:"webdav_export_password,omitempty"`            // 加密后的 WebDAV 备份密码
	WebDAVExportIncludeCredentials  bool   `json:"webdav_export_include_credentials,omitempty"`
	WebDAVExportIncludeForwards     bool   `json:"webdav_export_include_forwards,omitempty"`
	WebDAVExportIncludePolicyGroups bool   `json:"webdav_export_include_policy_groups,omitempty"`
	WebDAVExportIncludeShortcuts    bool   `json:"webdav_export_include_shortcuts,omitempty"`
	WebDAVExportIncludeThemes       bool   `json:"webdav_export_include_themes,omitempty"`
	LastUpdateCheck                 int64  `json:"last_update_check,omitempty"` // 上次自动检查更新的 Unix 时间戳
	DebugMode                       bool   `json:"debug_mode,omitempty"`        // 开启后日志级别降为 debug
	WindowWidth                     int    `json:"window_width,omitempty"`      // 上次正常窗口宽度
	WindowHeight                    int    `json:"window_height,omitempty"`     // 上次正常窗口高度

	// SSH 空闲保活心跳的全局默认间隔(秒),作用于所有出站 SSH 连接(终端会话 +
	// 连接池)。<=0 = 采用内置默认(30s)。单个资产可在其 SSH 配置里覆盖此值。
	SSHKeepAliveIntervalSeconds int `json:"ssh_keepalive_interval_seconds,omitempty"`

	// 外部编辑配置。仅持久化用户自定义编辑器;内置候选由运行时探测生成。
	ExternalEditDefaultEditorID      string                 `json:"external_edit_default_editor_id,omitempty"`
	ExternalEditWorkspaceRoot        string                 `json:"external_edit_workspace_root,omitempty"`
	ExternalEditCustomEditors        []ExternalEditorConfig `json:"external_edit_custom_editors,omitempty"`
	ExternalEditCleanupRetentionDays int                    `json:"external_edit_cleanup_retention_days,omitempty"`
	ExternalEditMaxReadFileSizeMB    int                    `json:"external_edit_max_read_file_size_mb,omitempty"`
}

AppConfig 应用持久化配置(config.json)

func GetConfig

func GetConfig() *AppConfig

GetConfig 获取当前配置(LoadConfig 之后调用)

func LoadConfig

func LoadConfig(dataDir string) (*AppConfig, error)

LoadConfig 加载应用配置,首次调用时自动生成默认值 必须在 Init 之后调用(依赖 dataDir)

type ExternalEditorConfig added in v1.7.0

type ExternalEditorConfig struct {
	ID   string   `json:"id"`
	Name string   `json:"name"`
	Path string   `json:"path"`
	Args []string `json:"args,omitempty"`
}

ExternalEditorConfig 是用户自定义外部编辑器配置。

type Options

type Options struct {
	DataDir   string // 空则用默认平台目录
	MasterKey string // 空则从 Keychain/文件自动获取或生成
}

Options 初始化选项

Jump to

Keyboard shortcuts

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