# 任务05:配置模型定义 ## 任务描述 定义Installer Builder项目的配置模型,包括安装包的基本信息、构建目标、文件和目录、脚本和依赖项等。配置模型将作为整个构建过程的基础,为后续的配置解析、验证和构建提供数据结构支持。 ## 实现步骤 1. 定义基本配置结构: - 在`internal/config/model`包中创建`config.go`文件 - 定义Config结构体,包含安装包的基本信息: ```go type Config struct { // 基本信息 Name string `yaml:"name" json:"name"` // 应用名称 Version string `yaml:"version" json:"version"` // 应用版本 Description string `yaml:"description" json:"description"` // 应用描述 Author string `yaml:"author" json:"author"` // 作者信息 License string `yaml:"license" json:"license"` // 许可证信息 // 构建目标 Targets []Target `yaml:"targets" json:"targets"` // 构建目标列表 // 文件和目录 Files []File `yaml:"files" json:"files"` // 要包含的文件 Directories []Directory `yaml:"directories" json:"directories"` // 要包含的目录 // 脚本 PreInstall Script `yaml:"preInstall" json:"preInstall"` // 安装前脚本 PostInstall Script `yaml:"postInstall" json:"postInstall"` // 安装后脚本 // 依赖 Dependencies []Dependency `yaml:"dependencies" json:"dependencies"` // 依赖项 // 插件配置 Plugins map[string]interface{} `yaml:"plugins" json:"plugins"` // 插件特定配置 } ``` 2. 定义构建目标结构: - 创建Target结构体,表示构建目标: ```go type Target struct { Platform string `yaml:"platform" json:"platform"` // 目标平台 (windows, linux) Arch string `yaml:"arch" json:"arch"` // 目标架构 (amd64, arm64) PackageType string `yaml:"packageType" json:"packageType"` // 包类型 (msi, deb, rpm, zip) OutputPath string `yaml:"outputPath" json:"outputPath"` // 输出路径 } ``` 3. 定义文件和目录结构: - 创建File结构体,表示要包含的文件: ```go type File struct { Source string `yaml:"source" json:"source"` // 源文件路径 Destination string `yaml:"destination" json:"destination"` // 目标路径 Permissions string `yaml:"permissions" json:"permissions"` // 文件权限 } ``` - 创建Directory结构体,表示要包含的目录: ```go type Directory struct { Source string `yaml:"source" json:"source"` // 源目录路径 Destination string `yaml:"destination" json:"destination"` // 目标路径 Permissions string `yaml:"permissions" json:"permissions"` // 目录权限 Recursive bool `yaml:"recursive" json:"recursive"` // 是否递归包含子目录 } ``` 4. 定义脚本结构: - 创建Script结构体,表示安装脚本: ```go type Script struct { Path string `yaml:"path" json:"path"` // 脚本文件路径 Type string `yaml:"type" json:"type"` // 脚本类型 (node, shell) Args []string `yaml:"args" json:"args"` // 脚本参数 } ``` 5. 定义依赖项结构: - 创建Dependency结构体,表示依赖项: ```go type Dependency struct { Name string `yaml:"name" json:"name"` // 依赖名称 Version string `yaml:"version" json:"version"` // 依赖版本 Type string `yaml:"type" json:"type"` // 依赖类型 } ``` 6. 实现配置模型的辅助方法: - 添加验证方法,用于基本验证 - 添加获取特定信息的方法 - 添加配置合并和克隆方法 7. 定义配置常量和默认值: - 定义支持的平台、架构和包类型常量 - 定义默认值和配置模板 ## 单元测试要求 1. 测试配置结构: - 验证结构体字段和标签 - 测试序列化和反序列化 2. 测试辅助方法: - 验证验证方法 - 测试获取特定信息的方法 - 测试配置合并和克隆方法 3. 测试常量和默认值: - 验证常量定义 - 测试默认值应用 ## 依赖关系 - 依赖任务01(项目初始化) - 被任务06(YAML配置解析器)和任务07(JSON配置解析器)依赖 ## 完成标准 1. 所有配置结构体已定义并文档完善 2. 结构体字段包含适当的标签,支持YAML和JSON序列化 3. 辅助方法已实现并测试通过 4. 常量和默认值已定义 5. 所有单元测试通过 6. 代码符合项目的Go语言开发规范 7. 配置模型能够满足需求文档中的所有配置需求