littlebot
Published on 2025-04-12 / 1 Visits
0

【源码】基于Go语言的Go2Fe一体化Web开发系统

项目简介

Go2Fe是一款基于Go语言开发的一体化Web开发框架,它整合了前后端开发所需的各项功能,旨在简化Web开发流程,帮助开发者高效构建稳定、高效的Web应用。

项目的主要特性和功能

  1. 数据模型注册:通过go2fe.RegModel()函数轻松注册数据模型,方便前端页面和接口配置的生成。
  2. 自动生成前端配置:依据注册的数据模型,自动生成前端所需的页面路径、API路径等配置信息。
  3. 测试支持:提供测试功能,执行go test可自动运行main_test.go中以Test开头的函数。
  4. HTTP服务器:基于Gin框架构建,具备基本的路由处理能力。
  5. 前端模板:提供前端模板代码,便于快速搭建前端页面。

安装使用步骤(假设用户已经下载了本项目的源码文件)

  1. 进入项目目录。
  2. 执行go run main.go,自动安装依赖并启动程序。
  3. (可选)执行go test进行单元测试。
  4. 使用go2fe:
    • 初始化项目:
      • 注册数据模型,参考如下示例: ``go // ComponentModel demo数据模型 type ComponentModel struct { ID stringjson:"ID" unique_key:"" show:"" title:"id"DisplayName stringjson:"DisplayName" show:"" title:"组件名"PackageName stringjson:"PackageName" show:"" title:"包名"DevListJSON stringjson:"DevListJSON" show:"" title:"开发者"Description stringjson:"Description" show:"" title:"描述"SiteURL stringjson:"SiteURL" show:"" title:"网站主页"Remark stringjson:"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)

} `` - 为每类数据模型实现getlistcreateupdateremove五个接口。 - 在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. 注意:clientstatic文件夹需要添加到.gitignore`中。

下载地址

点击下载 【提取码: 4003】【解压密码: www.makuang.net】