-
Notifications
You must be signed in to change notification settings - Fork 320
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
发布v2.15.1版本,更新内容请查看:https://github.com/bufanyun/hotgo/blob/v2.0/docs/…
- Loading branch information
Showing
445 changed files
with
17,293 additions
and
6,544 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
## 生成业务模板 | ||
|
||
根据`api`接口文件一键生成业务模板:api、controller、logic、service | ||
|
||
待写。 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,170 @@ | ||
## 生成配置 | ||
|
||
目录 | ||
|
||
- 模板配置 | ||
- CLI配置 | ||
- 多数据库使用 | ||
|
||
### 模板配置 | ||
|
||
- 配置路径:server/manifest/config/config.yaml | ||
|
||
```yaml | ||
# 生成代码 | ||
hggen: | ||
allowedIPs: [ "127.0.0.1", "*" ] # 白名单,*代表所有,只有允许的IP后台才能使用生成代码功能 | ||
selectDbs: [ "default" ] # 可选生成表的数据库配置名称,支持多库 | ||
disableTables: [ "hg_sys_gen_codes","hg_admin_role_casbin" ] # 禁用的表,禁用以后将不会在选择表中看到 | ||
delimiters: [ "@{", "}" ] # 模板引擎变量分隔符号 | ||
# 生成应用模型,所有生成模板允许自定义,可以参考default模板进行改造 | ||
application: | ||
# CRUD和关系树列表模板 | ||
crud: | ||
templates: | ||
# 默认的主包模板 | ||
- group: "default" # 分组名称 | ||
isAddon: false # 是否为插件模板 false|true | ||
masterPackage: "sys" # 主包名称,需和controllerPath、logicPath、inputPath保持关联 | ||
templatePath: "./resource/generate/default/curd" # 模板路径 | ||
apiPath: "./api/admin" # goApi生成路径 | ||
controllerPath: "./internal/controller/admin/sys" # 控制器生成路径 | ||
logicPath: "./internal/logic/sys" # 主要业务生成路径 | ||
inputPath: "./internal/model/input/sysin" # 表单过滤器生成路径 | ||
routerPath: "./internal/router/genrouter" # 生成路由表路径 | ||
sqlPath: "./storage/data/generate" # 生成sql语句路径 | ||
webApiPath: "../web/src/api" # webApi生成路径 | ||
webViewsPath: "../web/src/views" # web页面生成路径 | ||
|
||
# 默认的插件包模板,{$name}会自动替换成实际的插件名称 | ||
- group: "addon" # 分组名称 | ||
isAddon: true # 是否为插件模板 false|true | ||
masterPackage: "sys" # 主包名称,需和controllerPath、logicPath、inputPath保持关联 | ||
templatePath: "./resource/generate/default/curd" # 模板路径 | ||
apiPath: "./addons/{$name}/api/admin" # goApi生成路径 | ||
controllerPath: "./addons/{$name}/controller/admin/sys" # 控制器生成路径 | ||
logicPath: "./addons/{$name}/logic/sys" # 主要业务生成路径 | ||
inputPath: "./addons/{$name}/model/input/sysin" # 表单过滤器生成路径 | ||
routerPath: "./addons/{$name}/router/genrouter" # 生成路由表路径 | ||
sqlPath: "./storage/data/generate/addons" # 生成sql语句路径 | ||
webApiPath: "../web/src/api/addons/{$name}" # webApi生成路径 | ||
webViewsPath: "../web/src/views/addons/{$name}" # web页面生成路径 | ||
|
||
# 消息队列模板 | ||
queue: | ||
templates: | ||
- group: "default" | ||
templatePath: "./resource/generate/default/queue" | ||
|
||
# 定时任务模板 | ||
cron: | ||
templates: | ||
- group: "default" | ||
templatePath: "./resource/generate/default/cron" | ||
|
||
# 生成插件模块,通过后台创建新插件时使用的模板,允许自定义,可以参考default模板进行改造 | ||
addon: | ||
srcPath: "./resource/generate/default/addon" # 生成模板路径 | ||
webApiPath: "../web/src/api/addons/{$name}" # webApi生成路径 | ||
webViewsPath: "../web/src/views/addons/{$name}" # web页面生成路径 | ||
``` | ||
### CLI配置 | ||
- hotgo在生成dao、service配置时,默认了和gf官方一致的配置方式和代码生成规则。所以无论你是通过hotgo亦或gf命令生成,最终代码格式完全一致,遵循一致的代码规范。 | ||
- 配置路径:[server/hack/config.yaml](../../server/hack/config.yaml) | ||
```yaml | ||
gfcli: | ||
build: | ||
name: "hotgo" # 编译后的可执行文件名称 | ||
# arch: "all" #不填默认当前系统架构,可选:386,amd64,arm,all | ||
# system: "all" #不填默认当前系统平台,可选:linux,darwin,windows,all | ||
mod: "none" | ||
cgo: 0 | ||
packSrc: "resource" # 将resource目录打包进可执行文件,静态资源无需单独部署 | ||
packDst: "internal/packed/packed.go" # 打包后生成的Go文件路径,一般使用相对路径指定到本项目目录中 | ||
version: "" | ||
output: "./temp/hotgo" # 可执行文件生成路径 | ||
extra: "" | ||
|
||
gen: | ||
dao: | ||
- link: "mysql:hotgo:hg123456.@tcp(127.0.0.1:3306)/hotgo?loc=Local&parseTime=true" | ||
group: "default" # 分组 使用hotgo代码生成功能时必须填 | ||
# tables: "" # 指定当前数据库中需要执行代码生成的数据表。如果为空,表示数据库的所有表都会生成。 | ||
tablesEx: "hg_sys_addons_install" # 指定当前数据库中需要排除代码生成的数据表。 | ||
removePrefix: "hg_" | ||
descriptionTag: true | ||
noModelComment: true | ||
jsonCase: "CamelLower" | ||
gJsonSupport: true | ||
clear: true | ||
|
||
service: # 生成业务配置 | ||
srcFolder: "internal/logic" | ||
dstFolder: "internal/service" | ||
dstFileNameCase: "CamelLower" | ||
clear: true | ||
``` | ||
### 多数据库使用 | ||
- 假设我们要增加一个库名为`hotgo2`、分组为`default2`的数据库,并要为其生成代码 | ||
|
||
1. 配置[server/hack/config.yaml](../../server/hack/config.yaml) 如下: | ||
```yaml | ||
gen: | ||
dao: | ||
- link: "mysql:hotgo:hg123456.@tcp(127.0.0.1:3306)/hotgo?loc=Local&parseTime=true" | ||
group: "default" # 分组 使用hotgo代码生成功能时必须填 | ||
tablesEx: "hg_sys_addons_install" # 指定当前数据库中需要排除代码生成的数据表。 | ||
removePrefix: "hg_" | ||
descriptionTag: true | ||
noModelComment: true | ||
jsonCase: "CamelLower" | ||
gJsonSupport: true | ||
clear: false | ||
- link: "mysql:hotgo2:hg123456.@tcp(127.0.0.1:3306)/hotgo2?loc=Local&parseTime=true" | ||
group: "default2" # 分组 使用hotgo代码生成功能时必须填 | ||
tablesEx: "hg_sys_addons_install" # 指定当前数据库中需要排除代码生成的数据表。 | ||
removePrefix: "" | ||
descriptionTag: true | ||
noModelComment: true | ||
jsonCase: "CamelLower" | ||
gJsonSupport: true | ||
clear: false | ||
``` | ||
|
||
2. 配置`server/manifest/config/config.yaml`, | ||
|
||
`database`配置如下: | ||
```yaml | ||
database: | ||
logger: | ||
level: "all" | ||
stdout: true | ||
default: | ||
link: "mysql:hotgo:hg123456.@tcp(127.0.0.1:3306)/hotgo?loc=Local&parseTime=true" | ||
debug: true | ||
Prefix: "hg_" | ||
default2: | ||
link: "mysql:hotgo2:hg123456.@tcp(127.0.0.1:3306)/hotgo2?loc=Local&parseTime=true" | ||
debug: true | ||
Prefix: "" | ||
``` | ||
|
||
`hggen`配置如下: | ||
```yaml | ||
hggen: | ||
allowedIPs: ["127.0.0.1", "*"] # 白名单,*代表所有,只有允许的IP后台才能使用生成代码功能 | ||
selectDbs: [ "default", "default2" ] # 可选生成表的数据库配置名称,支持多库 | ||
disableTables : ["hg_sys_gen_codes","hg_admin_role_casbin"] # 禁用的表,禁用以后将不会在选择表中看到 | ||
delimiters: ["@{", "}"] # 模板引擎变量分隔符号 | ||
``` | ||
|
||
3. 登录HotGo后台 -> 开发工具 -> 代码生成 -> 找到立即生成按钮并打开,就会发现`数据库`选项增加了一个`default2`,后续生成步骤和生成例子完全一样 | ||
|
||
> 注意:上述的配置中所有的`default2`名称必须保持一致 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,115 @@ | ||
## 生成关联表CURD | ||
|
||
### 热编译启动 | ||
- 推荐使用热编译方式启动HotGo,这样生成完成页面自动刷新即可看到新生成内容,无需手动重启 | ||
|
||
```shell | ||
# 服务端 | ||
cd server | ||
gf run main.go | ||
|
||
# web端 | ||
cd web | ||
yarn dev | ||
``` | ||
|
||
以下是一个关联表的CURD生成流程 | ||
|
||
### 创建表结构 | ||
- 以下表结构和数据为了方便功能演示已经内置无需再次创建 | ||
|
||
|
||
- 创建主表:hg_sys_gen_curd_demo | ||
```sql | ||
CREATE TABLE `hg_sys_gen_curd_demo` ( | ||
`id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT 'ID', | ||
`category_id` bigint(20) DEFAULT '0' COMMENT '分类ID', | ||
`title` varchar(64) NOT NULL COMMENT '标题', | ||
`description` varchar(255) DEFAULT '' COMMENT '描述', | ||
`content` text COMMENT '内容', | ||
`image` varchar(255) DEFAULT NULL COMMENT '单图', | ||
`attachfile` varchar(255) DEFAULT NULL COMMENT '附件', | ||
`city_id` bigint(20) DEFAULT '0' COMMENT '所在城市', | ||
`switch` int(11) DEFAULT '1' COMMENT '显示开关', | ||
`sort` int(11) DEFAULT NULL COMMENT '排序', | ||
`status` tinyint(1) DEFAULT '1' COMMENT '状态', | ||
`created_by` bigint(20) DEFAULT '0' COMMENT '创建者', | ||
`updated_by` bigint(20) DEFAULT '0' COMMENT '更新者', | ||
`created_at` datetime DEFAULT NULL COMMENT '创建时间', | ||
`updated_at` datetime DEFAULT NULL COMMENT '修改时间', | ||
`deleted_at` datetime DEFAULT NULL COMMENT '删除时间', | ||
PRIMARY KEY (`id`) | ||
) ENGINE=InnoDB AUTO_INCREMENT=14 DEFAULT CHARSET=utf8mb4 COMMENT='系统_生成curd演示'; | ||
``` | ||
|
||
创建关联表:hg_test_category | ||
```sql | ||
CREATE TABLE `hg_test_category` ( | ||
`id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT '分类ID', | ||
`name` varchar(255) NOT NULL COMMENT '分类名称', | ||
`short_name` varchar(128) DEFAULT NULL COMMENT '简称', | ||
`description` varchar(255) DEFAULT NULL COMMENT '描述', | ||
`sort` int(11) NOT NULL COMMENT '排序', | ||
`remark` varchar(255) DEFAULT NULL COMMENT '备注', | ||
`status` tinyint(1) DEFAULT '1' COMMENT '状态', | ||
`created_at` datetime DEFAULT NULL COMMENT '创建时间', | ||
`updated_at` datetime DEFAULT NULL COMMENT '修改时间', | ||
`deleted_at` datetime DEFAULT NULL COMMENT '删除时间', | ||
PRIMARY KEY (`id`) | ||
) ENGINE=InnoDB AUTO_INCREMENT=5 DEFAULT CHARSET=utf8mb4 COMMENT='测试分类'; | ||
``` | ||
|
||
### 表字段要求 | ||
- 使用生成时,表中必须具有以下字段和属性 | ||
|
||
| 字段名称 | 字段含义 | 字段类型 | 可为空 | | ||
|--------|----------------------|---------------------|-----| | ||
| id | 主键ID | bigint(20) | 否 | | ||
|
||
|
||
|
||
### 创建生成配置 | ||
- 登录HotGo后台 -> 开发工具 -> 代码生成 -> 找到立即生成按钮并打开,选择和填写如下参数: | ||
|
||
 | ||
|
||
|
||
### 基本设置 | ||
- 确认无误后,点击生成配置会跳转到生成配置页面,如下: | ||
- 你可以在该页面调整生成表格表头/表列的接口功能、菜单权限、高级设置和关联表设置 | ||
|
||
 | ||
|
||
### 主表字段设置 | ||
|
||
- 在该页面你可以调整生成表格字段名称、表单组件、表单编辑/验证项、列表展示/查询项、字段排序、重置和同步字段 | ||
|
||
 | ||
|
||
|
||
### 关联表字段设置 | ||
- 在该页面你可以调整生成表格关联表字段名称、列表展示/查询项、字段排序、重置和同步字段 | ||
- 如果存在多个关联表,也可以对多个关联表字段进行设置 | ||
|
||
 | ||
|
||
### 预览并生成 | ||
|
||
点击`预览代码`查看生成的代码内容。如果无需继续调整直接点击`提交生成`即可,以下是预览代码效果: | ||
|
||
 | ||
|
||
- 如果你使用的热编译,那么页面会在生成成功后立即刷新,刷新完成你即可在后台菜单栏中看到`测试表格`菜单。如果不是使用热编译启动,请手动重启服务后刷新。 | ||
|
||
|
||
### 生成完成 | ||
|
||
- 让我们看看生成的表格页面,效果如下: | ||
|
||
 | ||
|
||
### 常见问题 | ||
|
||
- [生成常见问题](code-help.md) | ||
|
||
|
Oops, something went wrong.