{"id":14956785,"url":"https://github.com/wangshibiaoflytiger/apiproject","last_synced_at":"2025-05-08T00:20:53.364Z","repository":{"id":40528208,"uuid":"202252108","full_name":"wangshibiaoFlytiger/apiproject","owner":"wangshibiaoFlytiger","description":"[https://www.sofineday.com], golang项目开发脚手架,集成最佳实践(gin+gorm+go-redis+mongo+cors+jwt+json日志库zap(支持日志收集到kafka或mongo)+消息队列kafka+微信支付宝支付gopay+api加密+api反向代理+go modules依赖管理+headless爬虫chromedp+makefile+二进制压缩+livereload热加载)","archived":false,"fork":false,"pushed_at":"2022-08-18T14:42:45.000Z","size":6774,"stargazers_count":180,"open_issues_count":3,"forks_count":39,"subscribers_count":6,"default_branch":"master","last_synced_at":"2024-12-27T10:07:27.359Z","etag":null,"topics":["alipay","api-server","compress","cors","gin-framework","golang","gomodule","gorm","headless","jwt","kafka","livereload","makefile","mongo","redis","reverseproxy","spider","wxpay","zap"],"latest_commit_sha":null,"homepage":"https://www.sofineday.com","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/wangshibiaoFlytiger.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2019-08-14T01:45:15.000Z","updated_at":"2024-12-26T05:50:17.000Z","dependencies_parsed_at":"2022-08-30T02:12:08.491Z","dependency_job_id":null,"html_url":"https://github.com/wangshibiaoFlytiger/apiproject","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wangshibiaoFlytiger%2Fapiproject","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wangshibiaoFlytiger%2Fapiproject/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wangshibiaoFlytiger%2Fapiproject/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wangshibiaoFlytiger%2Fapiproject/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/wangshibiaoFlytiger","download_url":"https://codeload.github.com/wangshibiaoFlytiger/apiproject/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":231468021,"owners_count":18381174,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["alipay","api-server","compress","cors","gin-framework","golang","gomodule","gorm","headless","jwt","kafka","livereload","makefile","mongo","redis","reverseproxy","spider","wxpay","zap"],"created_at":"2024-09-24T13:13:31.441Z","updated_at":"2024-12-27T10:07:32.489Z","avatar_url":"https://github.com/wangshibiaoFlytiger.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"_**若本项目给您带来收获, 还请您动动小拇指,右上角给点个赞哈,万分感谢哈哈!!!**_\n\n项目原始仓库地址: https://github.com/wangshibiaoFlytiger/apiproject  \n欢迎关注官方微信公众号,及时收到一手技术资料!  \n![微信公众号二维码](\u003chttps://gitee.com/wangshibiao/blog_picBed2/raw/master/images/qrcode_for_gh_66d82451d714_258(1).jpg\u003e \"微信公众号二维码\")\n\n# 1. 博客地址\n\nhttps://www.sofineday.com\n\n这 2 天刚开始搭建, 后面会逐步完善功能,性能和内容等, 望收藏, 有任何疑问请提交 issue, 谢谢!\n\n_**欢迎加作者微信645102170或进群共同交流, 请扫下方二维码. 请备注 sofineday:smile:**_  \n![](https://i.loli.net/2020/07/16/5X1HohKICW7knlL.jpg)\n\n\u003e 目标是归纳出平时经常用到的重要知识点, 作为日后的枕边工具书\n\n# 2. 工程创建\n\nmkdir ./apiproject\n\ncd ./apiproject\n\ngo mod init apiproject\n\ngo build\n\n# 3. 集成 gin web 框架\n\ngo get github.com/gin-gonic/gin\n\ngo get github.com/go-sql-driver/mysql\n\ngo get github.com/jinzhu/gorm\n\n# 4. 项目规范\n\n## 4.1 包名追加前缀\n\nmodel 层: m\\_\n\ndao 层: d\\_\n\nservice 层: s\\_\n\ncontroller 层: c\\_\n\n## 4.2 文件名或 struct 名称定义规范\n\n每一层的文件名或类名以所属层为后缀, model 层例外\n\n# 5. 测试代码\n\n执行单元测试, 需要进入 test 目录, 然后执行 go test\n\n# 6. live reload 自动编译并运行\n\ngo get -u github.com/cosmtrek/air\n\n项目根目录创建 liveReload.conf 文件:\n\n编辑配置项 bin,full_bin,exclude_file(将 rice-box.go 移除)\n\n启动 liveReload 服务\n\n```\n air -c ./liveReload.conf\n```\n\n# 7. 集成自动测试框架 goconvey\n\ngo get github.com/smartystreets/goconvey\n\n# 8. 支持跨域\n\ngo get github.com/gin-contrib/cors\n\n\u003e 此外还需要如下显示指定 ugorji/go 的版本, 使用 \u003e v1.1.2 版本,最新版本会出现包冲突错误:cannot load github.com/ugorji/go/codec: ambiguous import: found github.com/ugorji/go/codec in multiple modules\n\u003e go get github.com/ugorji/go@v1.1.2\n\n# 9. 指定运行环境\n\n通过指定命令行参数--profile 参数来加载对应的配置文件, 取值范围:dev,test,pro.\n\n可通过执行帮助命令查看./apiproject help\n\n# 10. 打包静态文件到可执行文件\n\ngo get github.com/GeertJohan/go.rice/...\n\n执行 go build 之前, 执行如下命令, 将项目中所有引用 rice.MustFindBox 或 rice.FindBox 的所属文件路径, 作为--import-path 的参数\n\n```\nrice -v --import-path \"./router\" --import-path \"./config\" embed-go\n```\n\n**注意事项**\n\n1. rice.MustFindBox 的路径参数不能为绝对路径, 且必须为字符串字面量, 不能为字符串变量\n2. 最终的静态文件路径不能以./开头, 否则报错, 如错误写法 box.MustBytes(\"./config_dev.ini\"), 正确写法 box.MustBytes(\"config_dev.ini\")\n3. 每次修改相应的静态文件, 记得随时执行 rice 命令,　否则会导致程序读取的文件内容不是最新的\n4. 把 box 理解为目录即可\n\n# 11. 压缩可执行文件\n\n## 11.1 优化编译参数\n\ngo build 增加如下编译参数\n\n```\n   -ldflags \"-s -w\"\n```\n\n## 11.2 使用 upx 压缩工具进一步压缩\n\n下载地址:https://github.com/upx/upx/releases\n\n使用方法\n\n```\nupx --brute 可执行文件路径\n```\n\n# 12. git 分支约定\n\n## 12.1 master 分支放通用功能, 目标是打造成 1 个通用框架\n\n## 12.2 创建实际项目的操作\n\n创建项目主分支\n\n```\ngit checkout -b 项目名称_master\n```\n\n创建针对该项目的分支\n\n```\ngit checkout 项目名称_master\ngit checkout -b 项目名称_branch_当前时间\n```\n\n合并项目分支到项目主分支\n\n```\ngit checkout 项目名称_master\n```\n\n合并项目分支到项目主分支\n\n合并通用框架的递增功能到项目分支(可以作为通用的功能一定要在 master 分支中开发)\n\n# 13. 分布式 ID 生成库\n\ngo get github.com/bwmarrin/snowflake\n\n# 14. kafka 消息队列\n\nconfluent-kafka-go 在后期使用过程中, kafka 服务端报未知异常, 故舍弃该客户端, 改用 sarama\n\n# 15. 纯真 ip 归属地查询\n\n## 15.1 安装\n\n直接执行如下命令会提示安装失败\n\n```\nmalformed module path \"github.com/kayon/iploc/...\": double dot\n```\n\n经实践, 顺序执行如下 2 个命令即可完成安装, 原因未知\n\n```\ngo get -u github.com/kayon/iploc/\ngo get -u github.com/kayon/iploc/...\n```\n\n## 15.2 下载纯真数据库文件\n\niploc-fetch qqwry.gbk.dat\n\n## 15.3 将 IP 库文件的编码转换为 UTF-8\n\niploc-conv -s qqwry.gbk.dat -d qqwry.utf8.dat\n\n## 16. 请作者喝杯:coffee:\n\n**若本项目给您带来收获，就请作者喝杯咖啡吧, 请备注 sofineday, 谢谢:smile:**\n| 微信 | 支付宝 |\n| ------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------- |\n| ![微信](https://cdn.jsdelivr.net/gh/wangshibiaoFlytiger/blog_picBed1/images/微信.jpg) | ![支付宝](https://cdn.jsdelivr.net/gh/wangshibiaoFlytiger/blog_picBed1/images/支付宝.jpg) |\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwangshibiaoflytiger%2Fapiproject","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fwangshibiaoflytiger%2Fapiproject","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwangshibiaoflytiger%2Fapiproject/lists"}