Files
2026-04-28 10:29:02 +08:00

68 lines
2.7 KiB
Go
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
package codegen
// GenConfig 代码生成完整配置
type GenConfig struct {
DbConfig DbConfig `json:"dbConfig"`
OutputDir string `json:"outputDir"` // 后端输出目录,绝对路径,为空则输出到项目根目录
FrontendOutputDir string `json:"frontendOutputDir"` // 前端输出目录,绝对路径,为空则跳过前端生成
Overwrite bool `json:"overwrite"` // true=覆盖已有文件 false=增量模式(跳过已存在文件)
Modules []Module `json:"modules"`
}
// DbConfig 目标数据库连接配置
type DbConfig struct {
Host string `json:"host"`
Port string `json:"port"`
User string `json:"user"`
Password string `json:"password"`
DbName string `json:"dbName"`
DbType string `json:"dbType"` // mysql / postgres / sqlite
}
// Module 模块定义(对应一组功能)
type Module struct {
Name string `json:"name"` // 模块名(PascalCase),如 "Order"
PackageName string `json:"packageName"` // 包名(lowercase),如 "order"
Description string `json:"description"`
Features []Feature `json:"features"`
}
// Feature 功能单元(对应一张表 / 一个实体)
type Feature struct {
Name string `json:"name"` // 实体名(PascalCase),如 "Product"
TableName string `json:"tableName"` // 数据库表名,如 "product"
Comment string `json:"comment"`
Fields []Field `json:"fields"`
Relations []Relation `json:"relations"`
}
// Field 字段定义
type Field struct {
Name string `json:"name"` // Go 字段名(PascalCase),如 "OrderNo"
ColumnName string `json:"columnName"` // 数据库列名(snake_case),如 "order_no"
Type string `json:"type"` // Go 类型,如 string / int / float64 / bool / time.Time
GormTag string `json:"gormTag"` // gorm tag 附加内容,如 "size:100;not null"
JsonTag string `json:"jsonTag"` // json tag,如 "orderNo"
Comment string `json:"comment"` // 字段注释
Required bool `json:"required"` // 是否必填(影响 not null
}
// Relation 表关系定义
type Relation struct {
Type string `json:"type"` // OneToOne / OneToMany / ManyToMany
TargetFeature string `json:"targetFeature"` // 目标实体名(PascalCase
ForeignKey string `json:"foreignKey"` // 外键字段名,如 "UserId"
JoinTable string `json:"joinTable"` // ManyToMany 中间表名
FieldName string `json:"fieldName"` // Go 中关联字段名,如 "Tags"
}
// TestConnectionReq 测试连接请求
type TestConnectionReq struct {
DbConfig DbConfig `json:"dbConfig"`
}
// PreviewReq 预览代码请求
type PreviewReq struct {
GenConfig
}