♻️ Refactor configuration service
This commit is contained in:
@@ -16,29 +16,24 @@ const (
|
||||
TabTypeTab TabType = "tab"
|
||||
)
|
||||
|
||||
// SaveOptions 保存选项
|
||||
type SaveOptions struct {
|
||||
// 自动保存延迟(毫秒)- 内容变更后多久自动保存
|
||||
AutoSaveDelay int `json:"autoSaveDelay"`
|
||||
// 变更字符阈值,超过此阈值立即触发保存
|
||||
ChangeThreshold int `json:"changeThreshold"`
|
||||
// 最小保存间隔(毫秒)- 两次保存之间的最小时间间隔,避免频繁IO
|
||||
MinSaveInterval int `json:"minSaveInterval"`
|
||||
}
|
||||
|
||||
// DocumentConfig 定义文档配置
|
||||
type DocumentConfig struct {
|
||||
SaveOptions SaveOptions `json:"saveOptions"` // 详细保存选项
|
||||
// 自动保存延迟(毫秒)- 内容变更后多久自动保存
|
||||
AutoSaveDelay int `json:"autoSaveDelay" yaml:"auto_save_delay" mapstructure:"auto_save_delay"`
|
||||
// 变更字符阈值,超过此阈值立即触发保存
|
||||
ChangeThreshold int `json:"changeThreshold" yaml:"change_threshold" mapstructure:"change_threshold"`
|
||||
// 最小保存间隔(毫秒)- 两次保存之间的最小时间间隔,避免频繁IO
|
||||
MinSaveInterval int `json:"minSaveInterval" yaml:"min_save_interval" mapstructure:"min_save_interval"`
|
||||
}
|
||||
|
||||
// EditorConfig 定义编辑器配置
|
||||
type EditorConfig struct {
|
||||
FontSize int `json:"fontSize"` // 字体大小
|
||||
EnableTabIndent bool `json:"enableTabIndent"` // 是否启用Tab缩进
|
||||
TabSize int `json:"tabSize"` // Tab大小
|
||||
TabType TabType `json:"tabType"` // Tab类型(空格或Tab)
|
||||
Language LanguageType `json:"language"` // 界面语言
|
||||
AlwaysOnTop bool `json:"alwaysOnTop"` // 窗口是否置顶
|
||||
FontSize int `json:"fontSize" yaml:"font_size" mapstructure:"font_size"` // 字体大小
|
||||
EnableTabIndent bool `json:"enableTabIndent" yaml:"enable_tab_indent" mapstructure:"enable_tab_indent"` // 是否启用Tab缩进
|
||||
TabSize int `json:"tabSize" yaml:"tab_size" mapstructure:"tab_size"` // Tab大小
|
||||
TabType TabType `json:"tabType" yaml:"tab_type" mapstructure:"tab_type"` // Tab类型(空格或Tab)
|
||||
Language LanguageType `json:"language" yaml:"language" mapstructure:"language"` // 界面语言
|
||||
AlwaysOnTop bool `json:"alwaysOnTop" yaml:"always_on_top" mapstructure:"always_on_top"` // 窗口是否置顶
|
||||
}
|
||||
|
||||
// LanguageType 语言类型定义
|
||||
@@ -53,35 +48,33 @@ const (
|
||||
|
||||
// PathsConfig 路径配置集合
|
||||
type PathsConfig struct {
|
||||
LogPath string `json:"logPath"` // 日志文件路径
|
||||
DataPath string `json:"dataPath"` // 数据存储路径
|
||||
DataPath string `json:"dataPath" yaml:"data_path" mapstructure:"data_path"` // 数据存储路径
|
||||
}
|
||||
|
||||
// AppConfig 应用配置 - 包含业务配置和路径配置
|
||||
type AppConfig struct {
|
||||
Editor EditorConfig `json:"editor"` // 编辑器配置
|
||||
Document DocumentConfig `json:"document"` // 文档配置
|
||||
Paths PathsConfig `json:"paths"` // 路径配置
|
||||
Metadata ConfigMetadata `json:"metadata"` // 配置元数据
|
||||
Editor EditorConfig `json:"editor" yaml:"editor" mapstructure:"editor"` // 编辑器配置
|
||||
Document DocumentConfig `json:"document" yaml:"document" mapstructure:"document"` // 文档配置
|
||||
Paths PathsConfig `json:"paths" yaml:"paths" mapstructure:"paths"` // 路径配置
|
||||
Metadata ConfigMetadata `json:"metadata" yaml:"metadata" mapstructure:"metadata"` // 配置元数据
|
||||
}
|
||||
|
||||
// ConfigMetadata 配置元数据
|
||||
type ConfigMetadata struct {
|
||||
Version string `json:"version"` // 配置版本
|
||||
LastUpdated time.Time `json:"lastUpdated"` // 最后更新时间
|
||||
Version string `json:"version" yaml:"version" mapstructure:"version"` // 配置版本
|
||||
LastUpdated time.Time `json:"lastUpdated" yaml:"last_updated" mapstructure:"last_updated"` // 最后更新时间
|
||||
}
|
||||
|
||||
// NewDefaultAppConfig 创建默认应用配置
|
||||
func NewDefaultAppConfig() *AppConfig {
|
||||
// 获取用户主目录
|
||||
homePath, err := os.UserHomeDir()
|
||||
// 获取当前工作目录
|
||||
currentDir, err := os.Getwd()
|
||||
if err != nil {
|
||||
homePath = "."
|
||||
currentDir = "."
|
||||
}
|
||||
|
||||
// 默认路径配置
|
||||
rootDir := filepath.Join(homePath, ".voidraft")
|
||||
dataDir := filepath.Join(rootDir, "data")
|
||||
// 默认路径配置 - 使用当前目录
|
||||
dataDir := filepath.Join(currentDir, "data")
|
||||
|
||||
return &AppConfig{
|
||||
Editor: EditorConfig{
|
||||
@@ -93,14 +86,11 @@ func NewDefaultAppConfig() *AppConfig {
|
||||
AlwaysOnTop: false,
|
||||
},
|
||||
Document: DocumentConfig{
|
||||
SaveOptions: SaveOptions{
|
||||
AutoSaveDelay: 5000, // 5秒后自动保存
|
||||
ChangeThreshold: 500, // 500个字符变更触发保存
|
||||
MinSaveInterval: 1000, // 最小间隔1000毫秒
|
||||
},
|
||||
AutoSaveDelay: 5000, // 5秒后自动保存
|
||||
ChangeThreshold: 500, // 500个字符变更触发保存
|
||||
MinSaveInterval: 1000, // 最小间隔1000毫秒
|
||||
},
|
||||
Paths: PathsConfig{
|
||||
LogPath: filepath.Join(rootDir, "logs"),
|
||||
DataPath: dataDir,
|
||||
},
|
||||
Metadata: ConfigMetadata{
|
||||
|
Reference in New Issue
Block a user