项目简介
Go2Fe是一款基于Go语言开发的一体化Web开发框架,它整合了前后端开发所需的各项功能,旨在简化Web开发流程,帮助开发者高效构建稳定、高效的Web应用。
项目的主要特性和功能
- 数据模型注册:通过
go2fe.RegModel()
函数轻松注册数据模型,方便前端页面和接口配置的生成。 - 自动生成前端配置:依据注册的数据模型,自动生成前端所需的页面路径、API路径等配置信息。
- 测试支持:提供测试功能,执行
go test
可自动运行main_test.go
中以Test
开头的函数。 - HTTP服务器:基于Gin框架构建,具备基本的路由处理能力。
- 前端模板:提供前端模板代码,便于快速搭建前端页面。
安装使用步骤(假设用户已经下载了本项目的源码文件)
- 进入项目目录。
- 执行
go run main.go
,自动安装依赖并启动程序。 - (可选)执行
go test
进行单元测试。 - 使用go2fe:
- 初始化项目:
- 注册数据模型,参考如下示例:
``go // ComponentModel demo数据模型 type ComponentModel struct { ID string
json:"ID" unique_key:"" show:"" title:"id"DisplayName string
json:"DisplayName" show:"" title:"组件名"PackageName string
json:"PackageName" show:"" title:"包名"DevListJSON string
json:"DevListJSON" show:"" title:"开发者"Description string
json:"Description" show:"" title:"描述"SiteURL string
json:"SiteURL" show:"" title:"网站主页"Remark string
json:"Remark" title:"备注"` }
- 注册数据模型,参考如下示例:
- 初始化项目:
func main() { customerModel := go2fe.ModelDefine{ DataModel: ComponentModel{}, Page: go2fe.Page{ Create: true, Update: true, Detail: true, }, Name: "测试模型", BasePath: "/component", BaseAPIPath: "/api/component", } go2fe.RegModel(customerModel)
if go2fe.Bootstrap() {
return
}
dbErr := model.InitDb()
log.Init(config.App.LogPathURI)
// log.Info("进程以server模式启动")
if dbErr != nil {
// log.Error("数据库初始化失败,程序退出")
return
}
r := router.InitRouter()
// 程序结束前关闭数据库链接
defer model.DB.Close()
r.Run(":" + config.App.Port)
}
``
- 为每类数据模型实现
get、
list、
create、
update、
remove五个接口。
- 在
main方法中添加
go2fe.Bootstrap()。
- 执行
go run main.go go2fe:init初始化文件夹,或者使用
go2fe.InitFeTemplate()。
- 执行
go run main.go go2fe:start启动前端测试环境,生成的前端代码位于
client文件夹中,也可使用
go2fe.StartDev()。
- 执行
go run main.go go2fe:build构建前端代码,生成的静态资源位于
static文件夹中,也可使用
go2fe.StartBuild()。
5. 注意:
client和
static文件夹需要添加到
.gitignore`中。
下载地址
点击下载 【提取码: 4003】【解压密码: www.makuang.net】