{"id":29112692,"url":"https://github.com/loveyu233/gb","last_synced_at":"2026-05-15T18:03:19.637Z","repository":{"id":294141476,"uuid":"984587113","full_name":"loveyu233/gb","owner":"loveyu233","description":"go web(简称gb)项目常用的一些方法函数小工具","archived":false,"fork":false,"pushed_at":"2025-06-25T01:43:30.000Z","size":287,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-06-25T02:39:57.587Z","etag":null,"topics":["decimal","gin","go","gorm","http","jwt","time","wx"],"latest_commit_sha":null,"homepage":"https://github.com/loveyu233/gb","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/loveyu233.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2025-05-16T07:11:01.000Z","updated_at":"2025-06-25T01:43:33.000Z","dependencies_parsed_at":"2025-06-05T07:29:44.910Z","dependency_job_id":"4a1ebb55-583f-4439-bdc2-6d97abda3eda","html_url":"https://github.com/loveyu233/gb","commit_stats":null,"previous_names":["loveyu233/gb"],"tags_count":54,"template":false,"template_full_name":null,"purl":"pkg:github/loveyu233/gb","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/loveyu233%2Fgb","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/loveyu233%2Fgb/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/loveyu233%2Fgb/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/loveyu233%2Fgb/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/loveyu233","download_url":"https://codeload.github.com/loveyu233/gb/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/loveyu233%2Fgb/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":262581282,"owners_count":23331908,"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":["decimal","gin","go","gorm","http","jwt","time","wx"],"created_at":"2025-06-29T11:02:07.273Z","updated_at":"2025-10-20T07:01:52.120Z","avatar_url":"https://github.com/loveyu233.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# gb: A Go Web Development Toolkit\n# Go Web 开发工具包\n\n\u003cdiv align=\"center\"\u003e\n\n![Go Version](https://img.shields.io/badge/Go-1.18+-blue)\n![License](https://img.shields.io/badge/license-MIT-green)\n![Build Status](https://img.shields.io/badge/build-passing-brightgreen)\n![Coverage](https://img.shields.io/badge/coverage-85%25-yellow)\n\n**一个为 Go Web 开发量身打造的、开箱即用的工具库，旨在简化开发流程，提升效率。**\n\n\u003c/div\u003e\n\n## 核心设计理念\n\n`gb` 遵循统一的初始化与调用模式，以简化资源管理和保证单例实例。\n\n- **初始化**: 所有模块的初始化函数均以 `Init` 为前缀，例如 `gb.InitGormDB()`。\n- **获取实例**: 初始化后，通过 `Ins` 前缀的函数获取该模块的唯一实例，例如 `gb.InsDB()`。\n\n```go\npackage main\n\nimport (\n\t\"fmt\"\n\t\"github.com/loveyu233/gb\"\n)\n\nfunc main() {\n\t// 示例：初始化并使用 GORM\n\terr := gb.InitGormDB(gb.GormConf{\n\t\t// ... 数据库配置\n\t})\n\tif err != nil {\n\t\tpanic(\"Failed to connect to database\")\n\t}\n\n\t// 在应用的任何地方，通过 InsDB() 获取 GORM 实例\n\tdb := gb.InsDB()\n\tfmt.Println(db)\n}\n```\n\n---\n\n## 🚀 功能特性\n\n### 🌐 Web 与 API 框架 (基于 Gin)\n- **Gin 快速启动**: 内置 Engine，并集成了一系列即用型中间件。\n- **中间件套件**: 提供 `CORS`, `Trace-ID`, `请求日志`, `Recovery` 等常用中间件。\n- **JWT 认证**: 基于 `jwt/v5` 的完整解决方案，支持 Token 生成、解析与刷新。\n- **Swagger 文档**: 自动生成 API 文档，方便接口调试与测试。\n- **参数验证**: 集成 `validator/v10`，支持自定义规则和多语言错误提示。\n- **标准化响应**: 提供统一的 JSON 响应封装，简化 API 输出。\n\n### 🗃️ 数据与存储\n- **ORM 数据库**: 深度集成 `GORM`，提供便捷的数据库操作。\n- **Redis**: 内置 `go-redis` 客户端，简化缓存、队列等操作。\n- **RedSync 分布式锁**: 基于 Redis 实现的分布式锁，确保并发安全。\n- **Excel 操作**: 使用 `excelize/v2`，轻松实现 Excel 导入导出及与结构体的映射。\n- **高精度计算**: 内置 `Decimal` 处理，避免浮点数计算的精度问题。\n\n### 🛠️ 核心工具\n- **结构化日志**: 基于 `zerolog` 的高性能结构化日志，支持多种输出格式。\n- **Cron 定时任务**: 集成 `gocron`，提供流畅的 API 来安排定时作业。\n- **HTTP 客户端**: 集成 `Resty`，提供链式调用的 HTTP 请求体验。\n- **Goroutine 池**: 内置 `ants` 协程池，有效管理和复用 Goroutine，防止大规模泄露。\n- **ID 生成器**: 提供 `Snowflake` 雪花算法和 `XID`，适用于分布式ID生成。\n- **密码安全**: 内置 `Bcrypt` 密码哈希与验证功能。\n- **Lua 脚本**: 集成 Lua 引擎，方便执行动态脚本。\n- **辅助函数库**: 预集成 `lo` (Lodash for Go), `gjson`, `copier`, `cast` 等热门工具库，极大提升开发效率。\n\n---\n\n## 🌱 生态系统\n\n为了保持 `gb` 核心库的轻量和专注，部分功能已被拆分到独立的模块中，您可以按需引入：\n\n- **支付集成 (Pay)**: 支付宝、微信支付等功能。\n  - [https://github.com/loveyu233/pay](https://github.com/loveyu233/pay)\n- **消息推送 (Msg)**: 企业微信机器人、短信发送等。\n  - [https://github.com/loveyu233/msg](https://github.com/loveyu233/msg)\n- **服务连接 (Connection)**: ETCD、RocketMQ 等。\n  - [https://github.com/loveyu233/connection](https://github.com/loveyu233/connection)\n- **图形验证码快速生成 (Captcha)**: 滑块，旋转，点击 等。\n    - [https://github.com/loveyu233/captcha](https://github.com/loveyu233/captcha)\n- **快速登录（login）**：集成了微信小程序的一键登录\n    - [https://github.com/loveyu233/login](https://github.com/loveyu233/login)\n---\n\n**⭐ 如果这个项目对你有帮助，请给我们一个 Star！⭐**\n\nMade with ❤️ by [loveyu233](https://github.com/loveyu233)","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Floveyu233%2Fgb","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Floveyu233%2Fgb","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Floveyu233%2Fgb/lists"}