Go 工程化项目结构思考
最近公司的项目需要进行一次新框架的搭建,由我和另外一位同事进行负责 @fanglina,在参考了多个优秀开源项目之后,想对此做出一部分总结。
参考项目:
- https://github.com/qit-team/snow
- https://github.com/go-kratos/kratos
- https://github.com/eminlin/bb-go
- https://github.com/cloudreve/Cloudreve
- https://github.com/studygolang/studygolang
- https://github.com/golang-standards/project-layout/blob/master/README_zh.md
- https://github.com/shockerli/go-awesome
先看一下大概的规划情况:
/app
存放不同的应用项目/admin
后台/cron
定时脚本/extend
第三方接口服务
/bootstrap
初始化项目/common
公共包/conf
配置文件方法/hooks
回调方法/postgresql
数据库连接、升级/rabbitmq
rabbitMQ 连接/redis
redis 连接/util
工具
/docs
项目文档conf.ini
配置文件
main.go
项目入口
针对单个 app
,例如 app/admin
项目为例,可以再细分:
/config
项目配置文件,每个项目可以单独区分配置文件/const
公共常量/handler
/http
/code
全局状态码、全局消息提示/controller
控制器/entities
结构体route.go
路由
/middleware
Http 中间件/model
/script
存放 SQL 文件
/sdk
/service
/cache
/mq
/consume
消费者入口/publish
生产者入口
/third
其他方项目cmd.go
执行入口
也许可以用 tree 那种格式来排版,用MD的锁进其实过个几行就眼花了
不错,mark一下