Documentation
¶
Overview ¶
Package gencode 提供 Web 化低代码生成平台(对标 RuoYi 代码生成器): 在线查看数据库表/字段、编辑字段、同步表结构、一键生成 DDD 代码。
Index ¶
- func Register(app *iris.Application, prefix string, cfg Config) (iris.Party, error)
- type ColumnMeta
- type Config
- type GenResult
- type GeneratedFile
- type Meta
- type Service
- func (s *Service) AddColumn(ctx context.Context, tableName string, column ColumnMeta) error
- func (s *Service) DropColumn(ctx context.Context, tableName, columnName string) error
- func (s *Service) Generate(ctx context.Context, tableName string, force bool) (*GenResult, []string, error)
- func (s *Service) ListTables(ctx context.Context) ([]TableInfo, error)
- func (s *Service) Preview(ctx context.Context, tableName string) (*GenResult, error)
- func (s *Service) ReadTable(ctx context.Context, tableName string) (*TableMeta, error)
- func (s *Service) SyncTable(ctx context.Context, tableName string) (*TableMeta, error)
- type TableInfo
- type TableMeta
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Register ¶
Register 注册低代码生成平台:
GET <prefix> 管理页面(表列表/字段编辑/生成)
GET <prefix>/api/tables 表列表(+已生成标记)
GET <prefix>/api/tables/{t} 表详情(字段)
POST <prefix>/api/tables/{t}/columns 新增字段
DELETE <prefix>/api/tables/{t}/columns/{c} 删除字段
POST <prefix>/api/tables/{t}/sync 同步表结构
GET <prefix>/api/tables/{t}/preview 代码预览
POST <prefix>/api/tables/{t}/generate 生成代码(force=true 覆盖)
Types ¶
type ColumnMeta ¶
type ColumnMeta struct {
Name string `json:"name"` // 列名
DataType string `json:"data_type"` // 数据库类型(INTEGER/TEXT/VARCHAR...)
Length int `json:"length"` // 长度(0=无)
Nullable bool `json:"nullable"` // 是否可空
Default string `json:"default"` // 默认值(空=无)
Comment string `json:"comment"` // 注释
PrimaryKey bool `json:"primary_key"` // 是否主键
AutoIncr bool `json:"auto_incr"` // 是否自增
}
ColumnMeta 字段元数据。
type Config ¶
type Config struct {
// DB 数据库实例(元数据与生成记录使用;必填)。
DB *gorm.DB
// ModulePath 业务项目 module 路径(生成 import 用;必填)。
ModulePath string
// OutputDir 生成文件输出根目录(默认当前目录)。
OutputDir string
// Auth 管理接口认证中间件(推荐 webiris.Auth;nil 时仅限流)。
Auth iris.Handler
// RatePerSecond 管理接口限流(默认 5 QPS)。
RatePerSecond float64
}
Config 组件配置。
type GenResult ¶
type GenResult struct {
Table string `json:"table"`
Files []GeneratedFile `json:"files"`
RouteCode string `json:"route_code"` // 路由注册代码段(复制进 main.go)
}
GenResult 一次生成的输出。
type GeneratedFile ¶
type GeneratedFile struct {
Path string `json:"path"` // 相对项目路径(如 internal/model/test_mycat.go)
Content string `json:"content"` // 文件内容
Hash string `json:"hash"` // 内容哈希(覆盖比对用)
}
GeneratedFile 生成结果文件。
type Meta ¶
type Meta struct {
// contains filtered or unexported fields
}
Meta 元数据读取器(按驱动分支)。
func (*Meta) ListTables ¶
ListTables 读取全部业务表(排除系统表)。
type Service ¶
type Service struct {
// contains filtered or unexported fields
}
Service 低代码生成服务。
func NewService ¶
NewService 创建生成服务。
func (*Service) DropColumn ¶
DropColumn 删除字段(驱动支持时)。
func (*Service) Generate ¶
func (s *Service) Generate(ctx context.Context, tableName string, force bool) (*GenResult, []string, error)
Generate 生成代码并写入文件。 已生成过的表需要 force=true 才覆盖(返回待覆盖文件清单)。
func (*Service) ListTables ¶
ListTables 表列表(含生成标记)。
type TableInfo ¶
type TableInfo struct {
TableMeta
Generated bool `json:"generated"`
GeneratedAt *time.Time `json:"generated_at,omitempty"`
}
TableInfo 表 + 已生成标记。
type TableMeta ¶
type TableMeta struct {
Name string `json:"name"` // 表名
Comment string `json:"comment"` // 表注释
Columns []ColumnMeta `json:"columns"` // 字段
}
TableMeta 表元数据。
Click to show internal directories.
Click to hide internal directories.