Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Golang代码生成器,Gin + Gorm + Swagger + Redis + 定时任务 + 邮件

Notifications You must be signed in to change notification settings

LerDer/GoGenerator

Folders and files

NameName
Last commit message
Last commit date

Latest commit

History

45 Commits

Repository files navigation

GoGenerator代码生成器

golang代码生成器,go有很多代码生成器,不过都是命令行操作,不太直观。

所以开发了一个代码生成器插件,这个代码生成器采用插件的方式,用起来更加简单,已经发布到jetbrains插件市场。

插件地址:https://plugins.jetbrains.com/plugin/26613-gogenerator

使用方法

1、先创建一个空项目

image-20250221121658132

2、配置数据库连接,目前只支持MySQL数据库

image-20250221121825144


image-20250221121850663

点击插件,显示如下窗口

image-20250221122010216

配置数据库,测试连接,成功后会展示数据库表

image-20250221122159751


image-20250221122238810


image-20250221122302934

选择项目路径,填写作者,项目名称等信息

image-20250221122540861

3、选择需要生成种类,第一次需要选中初始化文件,点击OK,生成成功

image-20250221122709388


image-20250221122801898

4、检查配置

idea配置(idea要开发go需要下载Go插件)

image-20250221123118386


image-20250221122916003

GoLand配置

image-20250221123009209

在main.go中也有说明

image-20250221123228467

5、执行 go mod tidy 或 go mod download 下载依赖

image-20250221123306395

6、执行 swag init 命令自动生成swagger文档

要先安装swag命令

go install github.com/swaggo/swag/cmd/swag@latest

image-20250221123511636

如果表没有Comment会导致swagger生成报错

image-20250221123936002

image-20250221124018535


image-20250221124105770

8、测试一下接口

image-20250221124138638

9、日志打印(速度确实很快)

image-20250221124251937

日志文件

image-20250221124336601

10、第二次生成

很多配置已经保存了,不需要再次输入

image-20250221124658061

先点击测试连接按钮,获取表,不需要选中初始化文件,

不点击测试连接按钮也可以,可以直接输入表的名称

image-20250221124831162

11、打开 user_like_router.go ,把路由信息复制到main.go中

image-20250221124942513


image-20250221125059360

12、再次执行swag init 命令自动生成swagger文档

image-20250221125151801

image-20250221125243830

新的接口已经展示出来了。测试一下

image-20250221125355594

14、其他

支持跨域,https,在main.go中配置

image-20250221125600111

还有发送邮件和定时任务,redis

image-20250221125736240

试一下定时任务,每分钟打印一个hello world

image-20250221125842258


image-20250221130021692

15、最后

struct

image-20250221130109276

Api

image-20250221130145508

router

image-20250221130207031

service (支持事务)

image-20250221130244469

Api里面只提供了最基本的业务操作,具体业务还需要根据需求修改。

项目结构是一个表对应一个文件夹,可以根据自己的需求改变目录。

image-20250221130501426

对于想体验一下go,却又不知如何下手的朋友们,快来试试吧。

About

Golang代码生成器,Gin + Gorm + Swagger + Redis + 定时任务 + 邮件

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

AltStyle によって変換されたページ (->オリジナル) /