{"id":17727028,"url":"https://github.com/openapphub/gin-service","last_synced_at":"2026-02-09T21:13:05.930Z","repository":{"id":258772896,"uuid":"875614620","full_name":"openapphub/gin-service","owner":"openapphub","description":"Gin Restful Web API, Simple Single Golang Web Service","archived":false,"fork":false,"pushed_at":"2024-11-01T06:44:48.000Z","size":108,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-08-24T20:39:04.867Z","etag":null,"topics":["docker","gin","goredis","gorm","jwt","makefile","mvc","restful","session"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/openapphub.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2024-10-20T13:03:24.000Z","updated_at":"2024-11-01T06:44:52.000Z","dependencies_parsed_at":"2024-10-25T22:29:41.310Z","dependency_job_id":"3876f4c3-1adf-4891-b58a-66802c31b32e","html_url":"https://github.com/openapphub/gin-service","commit_stats":null,"previous_names":["openapphub/gin-service"],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/openapphub/gin-service","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/openapphub%2Fgin-service","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/openapphub%2Fgin-service/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/openapphub%2Fgin-service/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/openapphub%2Fgin-service/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/openapphub","download_url":"https://codeload.github.com/openapphub/gin-service/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/openapphub%2Fgin-service/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29281566,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-02-09T19:05:41.198Z","status":"ssl_error","status_checked_at":"2026-02-09T19:05:37.449Z","response_time":56,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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":["docker","gin","goredis","gorm","jwt","makefile","mvc","restful","session"],"created_at":"2024-10-25T18:00:22.155Z","updated_at":"2026-02-09T21:13:05.915Z","avatar_url":"https://github.com/openapphub.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# openapphub-go\n\n\u003e 项目基于大佬的 [singo](https://github.com/gourouting/singo) 二开修改, 调整了项目结构，加入了docker、makefile、AUTH_MODE（jwt or session）等内容。从头学习的话推荐跟着大佬的项目进行：\n\n- [让我们写个G站吧！Golang全栈编程实况](https://space.bilibili.com/10/channel/detail?cid=78794)\n\n- [仿B站的G站](https://github.com/Gourouting/giligili)\n\n- [Singo框架为移动端提供Token登录的案例](https://github.com/bydmm/singo-token-exmaple)\n\n-----\n\nopenapphub: Simple Single Golang Web Service\n\nopenapphub: 用最简单的架构，实现够用的框架，服务海量用户\n\nhttps://github.com/Gourouting/openapphub\n\n## 更新日志\n\n1. 已支持接口测试\n2. 已经支持go1.20，请安装这个版本的golang使用本项目\n3. 新增JWT认证支持\n4. 新增Swagger文档\n5. 新增 zap logs处理\n\n## 目的\n\n本项目采用了一系列Golang中比较流行的组件，可以以本项目为基础快速搭建Restful Web API\n\n## 特色\n\n本项目已经整合了许多开发API所必要的组件：\n\n1. [Gin](https://github.com/gin-gonic/gin): 轻量级Web框架，自称路由速度是golang最快的 \n2. [GORM](https://gorm.io/index.html): ORM工具。本项目需要配合Mysql使用 \n3. [Gin-Session](https://github.com/gin-contrib/sessions): Gin框架提供的Session操作工具\n4. [Go-Redis](https://github.com/go-redis/redis): Golang Redis客户端\n5. [godotenv](https://github.com/joho/godotenv): 开发环境下的环境变量工具，方便使用环境变量\n6. [Gin-Cors](https://github.com/gin-contrib/cors): Gin框架提供的跨域中间件\n7. [httpexpect](https://github.com/gavv/httpexpect): 接口测试工具\n8. [gzip](http://github.com/gin-contrib/gzip): 接口压缩\n8. [JWT-Go](https://github.com/golang-jwt/jwt): JWT认证支持\n9. [ulule-limiter](https://github.com/ulule/limiter/v3): 速率限制\n9. [Swagger](https://github.com/swaggo/gin-swagger): API文档生成工具\n10. [zap](https://github.com/uber-go/zap) :zap 高性能、结构化的日志库\n11. [secure](https://github.com/unrolled/secure): 为Go提供了一些安全相关的HTTP头\n10. 自行实现了国际化i18n的一些基本功能\n11. 本项目支持基于cookie的session和JWT两种认证方式\n\n本项目已经预先实现了一些常用的代码方便参考和复用:\n\n1. 创建了用户模型\n2. 实现了`/api/v1/user/register`用户注册接口\n3. 实现了`/api/v1/user/login`用户登录接口\n4. 实现了`/api/v1/user/me`用户资料接口(需要登录后获取session)\n5. 实现了`/api/v1/user/logout`用户登出接口(需要登录后获取session)\n6. 实现了`/api/v1/user/refresh`刷新JWT token接口\n\n本项目已经预先创建了一系列文件夹划分出下列模块:\n\n1. `cmd/api`: 主程序入口\n2. `database/migrations`: 数据库建表相关\n2. `internal/api`: MVC框架的controller，负责协调各部件完成任务\n3. `internal/model`: 数据库模型和数据库操作相关的代码\n4. `internal/service`: 负责处理比较复杂的业务，把业务代码模型化可以有效提高业务代码的质量\n5. `internal/serializer`: 储存通用的json模型，把model得到的数据库模型转换成api需要的json对象\n6. `pkg/cache`: redis缓存相关的代码\n7. `internal/auth`: 权限控制相关的代码\n8. `internal/middleware/rate_limiter`: 速率限制\n8. `internal/util`: 一些通用的小工具\n9. `internal/config`: 配置文件和配置加载相关的代码\n10. `internal/middleware`: 中间件相关的代码\n11. `test`: 测试用例\n\n## 环境变量\n\n项目在启动的时候依赖以下环境变量，但是在也可以在项目根目录创建.env文件设置环境变量便于使用(建议开发环境使用)\n\n```shell\nMYSQL_DSN=\"db_user:db_password@/db_name?charset=utf8\u0026parseTime=True\u0026loc=Local\" # Mysql连接地址\nREDIS_ADDR=\"127.0.0.1:6379\" # Redis端口和地址\nREDIS_PW=\"\" # Redis连接密码\nREDIS_DB=\"\" # Redis库从0到10\nSESSION_SECRET=\"setOnProducation\" # Seesion密钥，必须设置而且不要泄露\nGIN_MODE=\"debug\"\nLOG_LEVEL=\"debug\"\nAUTH_MODE=\"session\" # 认证模式，可选值：session 或 jwt\nJWT_SECRET=\"setOnProducation\" # JWT密钥，使用JWT认证模式时必须设置\nPORT=\"3000\" # 服务端口号\n```\n## Godotenv\n\n本项目使用[Godotenv](https://github.com/joho/godotenv)加载环境变量，在使用和部署项目的时候可以配置环境变量增加灵活性。\n\n## Go Mod\n\n本项目使用[Go Mod](https://github.com/golang/go/wiki/Modules)管理依赖。\n\n```shell\ngo mod download\n```\n\n## 运行\n\n```shell\ngo run cmd/api/main.go\n// or user make\nmake install\nmake dev-setup\nmake docker-up\nmake run\n```\n项目运行后启动在3000端口（可以通过PORT环境变量修改）\n\n## 编译\n\n```shell\ngo build -o openapphub cmd/api/main.go\n```\n\n## 接口测试\n\n本项目使用`httpexpect`进行接口测试，测试文件位于`test`目录下。运行测试：\n\n```\ngo test -v ./test\n```\n\n## Swagger文档\n\n本项目使用Swagger自动生成API文档。\n\n1. 安装swag\n   ```\n   go install github.com/swaggo/swag/cmd/swag@latest\n   ```\n\n2. 生成文档\n   ```\n   swag init -g cmd/api/main.go -o docs\n   ```\n\n3. 访问文档：启动服务后，访问 `http://localhost:3000/swagger/index.html`\n\n## Makefile\n\n项目根目录下的Makefile文件包含了常用的操作命令，使用make命令即可执行。\n\n## Docker支持\n\n本项目支持使用Docker进行部署，根目录下的Dockerfile文件已经配置好了相应的构建流程。\n\n## 贡献\n\n如果你有好的意见或建议，欢迎给我们提 issue 或 pull request。\n\n## 版权\n\nCopyright (c) 2024 Gourouting\n\nLicensed under the [MIT license](LICENSE)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fopenapphub%2Fgin-service","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fopenapphub%2Fgin-service","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fopenapphub%2Fgin-service/lists"}