发布日期: 2026-02-28
版本号: v1.12.0

本次更新对Gin框架进行了全面增强,主要包括:新增了URI/查询绑定中对编码、解码文本的支持,以及上下文中的错误获取方法和协议缓冲区内容协商功能;修复了绑定中空值处理、表单绑定中的空切片/数组、客户端IP处理等多个问题,解决了资源泄漏和路由匹配错误;进行了多项代码重构与优化,如简化映射处理、用常量替换魔法数字等,提升了性能与可读性;同时升级了相关依赖,改进了CI流程与文档,并扩展了测试覆盖率。

更新内容 (中文)

更新日志

功能特性

  • 192ac89eefc1c30f7c97ae48a9ffb1c6f1c8c8bc: feat(binding): 为uri/query绑定添加编码.UnmarshalText支持 (#4203) (@takanuva15)
  • 53410d2e07054369e0960fbe2eed97e1b9966f12: feat(context): 添加GetError和GetErrorSlice方法用于错误检索 (#4502) (@raju-mechatronics)
  • acc55e049e33b401e810dbd8c0d6dcb6b3ba2b05: feat(context): 为内容协商添加Protocol Buffers支持 (#4423) (@1911860538)
  • 38e765119241d990705169bedb5002a29ae0cbd1: feat(context): 实现Delete方法 (@Spyder01)
  • 771dcc6476d7bc6abb9ec0235ecefa4d38fe6fb0: feat(gin): 添加使用转义路径的选项 (#4420) (@ldesauw)
  • 4dec17afdff48e8018c83618fbbe69fceeb2b41d: feat(logger): 延迟颜色显示 (#4146) (@wsyqn6)
  • d7776de7d444935ea4385999711bd6331a98fecb: feat(render): 添加bson协议支持 (#4145) (@laurentcau)

错误修复

  • b917b14ff9d189f16a7492be79d123a47806ee19: fix(binding): 空值错误 (#2169) (@guonaihong)
  • c3d1092b3b48addf6f9cd00fe274ec3bd14650eb: fix(binding): 改进表单绑定中的空切片/数组处理 (#4380) (@1911860538)
  • 9914178584e42458ff7d23891463a880f58c9d86: fix(context): 处理多个X-Forwarded-For头值时的ClientIP (#4472) (@Nurysso)
  • 2a794cd0b0faa7d829291375b27a3467ea972b0d: fix(debug): 版本不匹配 (#4403) (@zeek0x)
  • c3d5a28ed6d3849da820195b6774d212bcc038a9: fix(gin): 在RunFd中关闭os.File以防止资源泄漏 (#4422) (@1911860538)
  • 5fad976b372e381312f8de69f0969f1284d229d3: fix(gin): 字面冒号路由与engine.Handler()无法配合工作 (#4415) (@pawannn)
  • 63dd3e60cab89c27fb66bce1423bd268d52abad1: fix(recover): 在recover中抑制http.ErrAbortHandler (#4336) (@MondayCha)
  • 5c00df8afadd06cc5be530dde00fe6d9fa4a2e4a: fix(render): 在Data.Render中写入内容长度 (#4206) (@dengaleev)
  • 234a6d4c00cb77af9852aca0b8289745d5529b4b: fix(response): 完善响应生命周期中的hijack行为 (#4373) (@appleboy)
  • 472d086af2acd924cb4b9d7be0525f7d790f69bc: fix(tree): 在findCaseInsensitivePathRec中使用RedirectFixedPath时发生panic (#4535) (@veeceey)
  • 8e07d37c63e5536eb25f4af4c91eabeee4011fba: fix: 修正拼写错误,提升文档清晰度,移除无用代码 (#4511) (@mahanadh)

增强改进

  • ba093d19477b896ac89a7fc3246af23d290b8e26: chore(binding): 将bson依赖升级至mongo-driver v2 (#4549) (@BobDu)
  • b2b489dbf4826c2c630717a77fd5e42774625410: chore(context): 始终信任来自unix套接字的xff头 (#3359) (@WeidiDeng)
  • ecb3f7b5e2f3915bf1db240ed5eee572f8dbea36: chore(deps): 将golang.org/x/crypto升级至v0.45.0 (#4449) (@appleboy)
  • af6e8b70b8261bb0c99ad094fe552ab92991620a: chore(deps): 将quic-go升级至v0.57.1 (@appleboy)
  • db309081bc5c137b2aa15701ef53f7f19788da25: chore(logger): 允许跳过查询字符串输出 (#4547) (@USA-RedDragon)
  • 26c3a628655cad2388380cb8102d6ce7d4875f3b: chore(response): 防止http.Flusher时发生Flush() panic (#4479) (@Twacqwq)
  • 5dd833f1f26de0eb30eae47b17e05ced2482dc41: chore: 将最低Go版本提升至1.24并更新工作流 (#4388) (@appleboy)

重构优化

  • 39858a0859c914bd26948fa950477e11bd8d3823: refactor(binding): 使用maps.Copy实现更简洁的map处理 (#4352) (@russcoss)
  • c0048f645ee945c4db30593afdea10123e2c30a6: refactor(context): 省略返回值名称 (#4395) (@wanghaolong613)
  • 915e4c90d28ec4cffc6eb146e208ab5a65eac772: refactor(context): 用常量替换硬编码的localhost IP (#4481) (@pauloappbr)
  • 414de60574449457f3192a7a1d5528940db2836d: refactor(context): 使用maps.Clone (#4333) (@cuiweixie)
  • 59e9d4a794f12c4f9a6c7bed441b9644e5f6d99b: refactor(ginS): 使用sync.OnceValue简化engine函数 (#4314) (@1911860538)
  • 3ab698dc5110af1977d57226e4995c57dd34c233: refactor(recovery): 智能错误比较 (#4142) (@zeek0x)
  • d1a15347b1e45a8ee816193d3578a93bfd73b70f: refactor(utils): 将工具函数移至utils.go (#4467) (@zeek0x)
  • e3118cc378d263454098924ebbde7e8d1dd2e904: refactor: for循环可通过range over int进行现代化 (#4392) (@wanghaolong613)
  • 488f8c3ffa579a8d19beb2bae95ff8ef36b3d53f: refactor: 用命名常量替换bodyAllowedForStatus中的魔数 (#4529) (@veeceey)
  • 9968c4bf9d5a99edc3eee2c068a4c9160ece8915: refactor: 使用b.Loop()简化代码并提升性能 (#4389) (@reddaisyy)
  • a85ef5ce4d0cda8834c59c855068ed48b51192d1: refactor: 使用b.Loop()简化代码并提升性能 (#4432) (@efcking)

构建流程更新

  • 61b67de522a189b568aced4c5c16917c558e3387: ci(bot): 增加依赖更新频率并分组更新 (#4367) (@appleboy)
  • fb27ef26c2fdfe25344b4c039d8a53551f9e912c: ci(lint): 重构测试断言和lint配置 (#4436) (@appleboy)
  • 93ff771e6dbf10e432864b30f3719ac5c84a4d4a: ci(sec): 提升HTTP中间件中的类型安全性和服务器组织结构 (#4437) (@appleboy)
  • e88fc8927a52b74f55bec0351604a56ac0aa1c51: ci(sec): 安排Trivy安全扫描每日UTC午夜运行 (#4439) (@appleboy)
  • 5e5ff3ace496a31b138b0820136a146bfb5de0ef: ci: 用Trivy集成替换漏洞扫描工作流 (#4421) (@appleboy)
  • 00900fb3e1ea9dde33985a0e4f6afec793d5e786: ci: 更新CI工作流并标准化Trivy配置引号 (#4531) (@appleboy)
  • ae3f524974fc4f55d18c9e7fae4614503c015226: ci: 在CI和文档中更新Go版本支持至1.25+ (#4550) (@appleboy)

文档更新

  • dceb61e6e76337b388109f6c553b026d3b6ff026: docs(README): 添加Trivy安全扫描徽章 (#4426) (@appleboy)
  • 58135f06cf206a9ff713eb14150ef04a05b031d4: docs(context): 为ShouldBind*方法添加示例注释 (#4428) (@AtoriUzawa)
  • c221133ee80c46e3a6c50717ca6f1b41d4ab7711: docs(context): 修正部分注释 (#4396) (@letreturn)
  • 731374fb3682af61cb153dabeec89aae401f1ede: docs(context): 修正注释中的错误函数名 (#4382) (@goldlinker)
  • 4dd00f81b1124d1a72e3d0fe050a224ff0ffcb88: docs(readme): 全面改进文档以提升清晰度和完整性 (#4362) (@appleboy)
  • 1bbbec0baf6370bfb74e07a9060292939534290d: docs: 发布Gin 1.11.0版本公告并附博客链接 (#4363) (@appleboy)
  • e292e5caa777bce70b66fe08c94cbe9cef3e2ec9: docs: 记录并确定Gin v1.12.0版本发布 (#4551) (@appleboy)
  • 792541470403dac0487b6213a22c7c2491084d83: docs: 改进GitHub贡献和支持模板 (#4364) (@appleboy)
  • 6a1d1218c3dbfc11427abc1ba39b86e81dff1e54: docs: 全面改进贡献指南并提供详细说明 (#4365) (@appleboy)
  • 73726dc606796a025971fe451f0aa6f1b9b847f6: docs: 更新文档以反映Go版本变更 (#4552) (@appleboy)
  • f3a5e787199f9ee1821fda15e93aec76737631ed: docs: 更新功能文档说明以修复文档链接失效问题 (@appleboy)

其他改进

  • 440eb14ab8ed503d4a31dfecc9946a90cd73b955: perf(path): 在redirectTrailingSlash中用自定义函数替代正则表达式 (#4414) (@1911860538)
  • 64a6ed9a41ab72076506bd590dc4b916ca4b66a5: perf(recovery): 优化stack函数中的行读取 (#4466) (@1911860538)
  • 2e22e5085960205fbb11c25776f6ea76b8053253: perf(tree): 使用strings.Count优化路径解析 (#4246) (@1911860538)
  • cad29c5e3f50a9764edbfc4787825c6caabd8579: perf(tree): 减少findCaseInsensitivePath中的内存分配 (#4417) (@arturmelanchyk)
  • ed150e72544949a96e7eb0b7d1151cf1907068fb: test(benchmarks): 修正错误的函数名 (#4375) (@mengxunQAQ)
  • 583db590ec2a488ebcf7f8dc6232d11c7db62eac: test(bytesconv): 为空值/nil情况添加测试 (#4454) (@miladev95)
  • fb2583442c4d9bccb75e6d26f1aa6e7c01950db6: test(context): 使用http.StatusContinue常量替代魔数100 (#4542) (@mehrdadbn9)
  • 19b877fa50cbbb9282763099fb177a1e5cc5c850: test(debug): 将debug.go测试覆盖率提升至100% (#4404) (@zeek0x)
  • c358d5656d0feb8b310d4ec379bccde46ccc8cc7: test(gin): 为ginS包添加全面测试覆盖 (#4442) (@miladev95)
  • f416d1e594a027063e73f66ac873a82113036fd8: test(gin): 解决集成测试中的竞态条件 (#4453) (@Planckbaka)
  • 6f1d5fe3cdb171a08928c3c9dd3fbcfc9ee1b521: test(render): 添加全面的错误处理测试 (#4541) (@Amirhf1)
  • 216a4a7c283bae102c4e365662566c895dbdad50: test(render): 为MsgPack渲染添加全面测试 (#4537) (@Amirhf1)

更新内容 (原始)

Changelog

Features

  • 192ac89eefc1c30f7c97ae48a9ffb1c6f1c8c8bc: feat(binding): add support for encoding.UnmarshalText in uri/query binding (#4203) (@takanuva15)
  • 53410d2e07054369e0960fbe2eed97e1b9966f12: feat(context): add GetError and GetErrorSlice methods for error retrieval (#4502) (@raju-mechatronics)
  • acc55e049e33b401e810dbd8c0d6dcb6b3ba2b05: feat(context): add Protocol Buffers support to content negotiation (#4423) (@1911860538)
  • 38e765119241d990705169bedb5002a29ae0cbd1: feat(context): implemented Delete method (@Spyder01)
  • 771dcc6476d7bc6abb9ec0235ecefa4d38fe6fb0: feat(gin): add option to use escaped path (#4420) (@ldesauw)
  • 4dec17afdff48e8018c83618fbbe69fceeb2b41d: feat(logger): color latency (#4146) (@wsyqn6)
  • d7776de7d444935ea4385999711bd6331a98fecb: feat(render): add bson protocol (#4145) (@laurentcau)

Bug fixes

  • b917b14ff9d189f16a7492be79d123a47806ee19: fix(binding): empty value error (#2169) (@guonaihong)
  • c3d1092b3b48addf6f9cd00fe274ec3bd14650eb: fix(binding): improve empty slice/array handling in form binding (#4380) (@1911860538)
  • 9914178584e42458ff7d23891463a880f58c9d86: fix(context): ClientIP handling for multiple X-Forwarded-For header values (#4472) (@Nurysso)
  • 2a794cd0b0faa7d829291375b27a3467ea972b0d: fix(debug): version mismatch (#4403) (@zeek0x)
  • c3d5a28ed6d3849da820195b6774d212bcc038a9: fix(gin): close os.File in RunFd to prevent resource leak (#4422) (@1911860538)
  • 5fad976b372e381312f8de69f0969f1284d229d3: fix(gin): literal colon routes not working with engine.Handler() (#4415) (@pawannn)
  • 63dd3e60cab89c27fb66bce1423bd268d52abad1: fix(recover): suppress http.ErrAbortHandler in recover (#4336) (@MondayCha)
  • 5c00df8afadd06cc5be530dde00fe6d9fa4a2e4a: fix(render): write content length in Data.Render (#4206) (@dengaleev)
  • 234a6d4c00cb77af9852aca0b8289745d5529b4b: fix(response): refine hijack behavior for response lifecycle (#4373) (@appleboy)
  • 472d086af2acd924cb4b9d7be0525f7d790f69bc: fix(tree): panic in findCaseInsensitivePathRec with RedirectFixedPath (#4535) (@veeceey)
  • 8e07d37c63e5536eb25f4af4c91eabeee4011fba: fix: Correct typos, improve documentation clarity, and remove dead code (#4511) (@mahanadh)

Enhancements

  • ba093d19477b896ac89a7fc3246af23d290b8e26: chore(binding): upgrade bson dependency to mongo-driver v2 (#4549) (@BobDu)
  • b2b489dbf4826c2c630717a77fd5e42774625410: chore(context): always trust xff headers from unix socket (#3359) (@WeidiDeng)
  • ecb3f7b5e2f3915bf1db240ed5eee572f8dbea36: chore(deps): upgrade golang.org/x/crypto to v0.45.0 (#4449) (@appleboy)
  • af6e8b70b8261bb0c99ad094fe552ab92991620a: chore(deps): upgrade quic-go to v0.57.1 (@appleboy)
  • db309081bc5c137b2aa15701ef53f7f19788da25: chore(logger): allow skipping query string output (#4547) (@USA-RedDragon)
  • 26c3a628655cad2388380cb8102d6ce7d4875f3b: chore(response): prevent Flush() panic when http.Flusher (#4479) (@Twacqwq)
  • 5dd833f1f26de0eb30eae47b17e05ced2482dc41: chore: bump minimum Go version to 1.24 and update workflows (#4388) (@appleboy)

Refactor

  • 39858a0859c914bd26948fa950477e11bd8d3823: refactor(binding): use maps.Copy for cleaner map handling (#4352) (@russcoss)
  • c0048f645ee945c4db30593afdea10123e2c30a6: refactor(context): omit the return value names (#4395) (@wanghaolong613)
  • 915e4c90d28ec4cffc6eb146e208ab5a65eac772: refactor(context): replace hardcoded localhost IPs with constants (#4481) (@pauloappbr)
  • 414de60574449457f3192a7a1d5528940db2836d: refactor(context): using maps.Clone (#4333) (@cuiweixie)
  • 59e9d4a794f12c4f9a6c7bed441b9644e5f6d99b: refactor(ginS): use sync.OnceValue to simplify engine function (#4314) (@1911860538)
  • 3ab698dc5110af1977d57226e4995c57dd34c233: refactor(recovery): smart error comparison (#4142) (@zeek0x)
  • d1a15347b1e45a8ee816193d3578a93bfd73b70f: refactor(utils): move util functions to utils.go (#4467) (@zeek0x)
  • e3118cc378d263454098924ebbde7e8d1dd2e904: refactor: for loop can be modernized using range over int (#4392) (@wanghaolong613)
  • 488f8c3ffa579a8d19beb2bae95ff8ef36b3d53f: refactor: replace magic numbers with named constants in bodyAllowedForStatus (#4529) (@veeceey)
  • 9968c4bf9d5a99edc3eee2c068a4c9160ece8915: refactor: use b.Loop() to simplify the code and improve performance (#4389) (@reddaisyy)
  • a85ef5ce4d0cda8834c59c855068ed48b51192d1: refactor: use b.Loop() to simplify the code and improve performance (#4432) (@efcking)

Build process updates

  • 61b67de522a189b568aced4c5c16917c558e3387: ci(bot): increase frequency and group updates for dependencies (#4367) (@appleboy)
  • fb27ef26c2fdfe25344b4c039d8a53551f9e912c: ci(lint): refactor test assertions and linter configuration (#4436) (@appleboy)
  • 93ff771e6dbf10e432864b30f3719ac5c84a4d4a: ci(sec): improve type safety and server organization in HTTP middleware (#4437) (@appleboy)
  • e88fc8927a52b74f55bec0351604a56ac0aa1c51: ci(sec): schedule Trivy security scans to run daily at midnight UTC (#4439) (@appleboy)
  • 5e5ff3ace496a31b138b0820136a146bfb5de0ef: ci: replace vulnerability scanning workflow with Trivy integration (#4421) (@appleboy)
  • 00900fb3e1ea9dde33985a0e4f6afec793d5e786: ci: update CI workflows and standardize Trivy config quotes (#4531) (@appleboy)
  • ae3f524974fc4f55d18c9e7fae4614503c015226: ci: update Go version support to 1.25+ across CI and docs (#4550) (@appleboy)

Documentation updates

  • dceb61e6e76337b388109f6c553b026d3b6ff026: docs(README): add a Trivy security scan badge (#4426) (@appleboy)
  • 58135f06cf206a9ff713eb14150ef04a05b031d4: docs(context): add example comments for ShouldBind* methods (#4428) (@AtoriUzawa)
  • c221133ee80c46e3a6c50717ca6f1b41d4ab7711: docs(context): fix some comments (#4396) (@letreturn)
  • 731374fb3682af61cb153dabeec89aae401f1ede: docs(context): fix wrong function name in comment (#4382) (@goldlinker)
  • 4dd00f81b1124d1a72e3d0fe050a224ff0ffcb88: docs(readme): revamp and expand documentation for clarity and completeness (#4362) (@appleboy)
  • 1bbbec0baf6370bfb74e07a9060292939534290d: docs: announce Gin 1.11.0 release with blog link (#4363) (@appleboy)
  • e292e5caa777bce70b66fe08c94cbe9cef3e2ec9: docs: document and finalize Gin v1.12.0 release (#4551) (@appleboy)
  • 792541470403dac0487b6213a22c7c2491084d83: docs: revamp GitHub contribution and support templates (#4364) (@appleboy)
  • 6a1d1218c3dbfc11427abc1ba39b86e81dff1e54: docs: revamp contributing guidelines with comprehensive instructions (#4365) (@appleboy)
  • 73726dc606796a025971fe451f0aa6f1b9b847f6: docs: update documentation to reflect Go version changes (#4552) (@appleboy)
  • f3a5e787199f9ee1821fda15e93aec76737631ed: docs: update feature documentation instructions for broken doc link (@appleboy)

Others

  • 440eb14ab8ed503d4a31dfecc9946a90cd73b955: perf(path): replace regex with custom functions in redirectTrailingSlash (#4414) (@1911860538)
  • 64a6ed9a41ab72076506bd590dc4b916ca4b66a5: perf(recovery): optimize line reading in stack function (#4466) (@1911860538)
  • 2e22e5085960205fbb11c25776f6ea76b8053253: perf(tree): optimize path parsing using strings.Count (#4246) (@1911860538)
  • cad29c5e3f50a9764edbfc4787825c6caabd8579: perf(tree): reduce allocations in findCaseInsensitivePath (#4417) (@arturmelanchyk)
  • ed150e72544949a96e7eb0b7d1151cf1907068fb: test(benchmarks): fix the incorrect function name (#4375) (@mengxunQAQ)
  • 583db590ec2a488ebcf7f8dc6232d11c7db62eac: test(bytesconv): add tests for empty/nil cases (#4454) (@miladev95)
  • fb2583442c4d9bccb75e6d26f1aa6e7c01950db6: test(context): use http.StatusContinue constant instead of magic number 100 (#4542) (@mehrdadbn9)
  • 19b877fa50cbbb9282763099fb177a1e5cc5c850: test(debug): improve the test coverage of debug.go to 100% (#4404) (@zeek0x)
  • c358d5656d0feb8b310d4ec379bccde46ccc8cc7: test(gin): Add comprehensive test coverage for ginS package (#4442) (@miladev95)
  • f416d1e594a027063e73f66ac873a82113036fd8: test(gin): resolve race conditions in integration tests (#4453) (@Planckbaka)
  • 6f1d5fe3cdb171a08928c3c9dd3fbcfc9ee1b521: test(render): add comprehensive error handling tests (#4541) (@Amirhf1)
  • 216a4a7c283bae102c4e365662566c895dbdad50: test(render): add comprehensive tests for MsgPack render (#4537) (@Amirhf1)

下载链接