gin v1.8.0 版本更新介绍
发布日期: 2022-05-30
版本号: v1.8.0
Gin框架更新日志包含以下变更:重大变更为TrustedProxies默认支持IPv6并重构RemoteIP方法(需替换旧方法),以及gin.Context从Request.Context()获取回退值。修复内容包括Go 1.17下SetOutput的panic问题、路由通配符与命名参数冲突问题、上下文重置时缺失sameSite的漏洞。功能增强涉及使用Header替代HeaderMap、路由匹配优化、支持go-json库、代码复杂度优化、自定义结构体标签、测试函数公开、h2c协议支持、UTF8附件名、新增StaticFileFS方法、测试模式自动切换及TOML绑定支持等。文档更新添加了nomsgpack标签说明。
更新内容 (中文)
更新日志
重大变更
- TrustedProxies: 新增默认 IPv6 支持并重构 #2967,请将
RemoteIP() (net.IP, bool)
替换为RemoteIP() net.IP
- 从 gin.Context.Request.Context() 获取备用值的 gin.Context #2751
错误修复
- 修复 Go 1.17 下 SetOutput() 触发 panic 的问题 #2861
- 修复通配符跟随命名参数时的路由匹配错误 #2983
- 修复 context.reset() 后丢失 sameSite 属性问题 #3123
功能增强
- 使用 Header() 替代已弃用的 HeaderMap #2694
- 优化 RouterGroup.Handle 的 HTTP 方法正则匹配 #2685
- 新增 go-json 支持,替代标准 JSON 库 #2680
- 使用 errors.New 替代 fmt.Errorf 以提升性能 #2707
- 使用 Duration.Truncate 进行时间精度截断 #2711
- 支持获取 Cloudflare 环境下的客户端 IP #2723
- 代码结构优化调整 #2700
- 代码优化与降低圈复杂度 #2737
- 从 gin.Context.Request.Context() 获取备用值的 gin.Context #2751
- 提升 sliceValidateError.Error 性能 #2765
- 支持自定义结构体标签 #2720
- 改进路由组测试用例 #2787
- 回退 Context.Deadline() Context.Done() Context.Err() 至 Context.Request.Context() #2769
- 多项代码优化 #2830 #2834 #2838 #2837 #2788 #2848 #2851 #2701
- 测试(route): 公开 performRequest 函数 #3012
- 支持 h2c 明文 HTTP/2 协议 #1398
- 附件文件名支持 UTF8 编码 #3071
- 新增 StaticFileFS 方法 #2749
- 特性(context): 通过 Value 方法返回 GIN 上下文 #2825
- 特性: 运行 go test 时自动切换至 TestMode #3139
- 新增 TOML 数据绑定支持 #3081
- IPv6 默认信任代理配置 #3033
文档更新
- 在 README 中添加关于 nomsgpack 标签的说明 #2703
更新内容 (原始)
Changelog
Break Changes
- TrustedProxies: Add default IPv6 support and refactor #2967. Please replace
RemoteIP() (net.IP, bool)
withRemoteIP() net.IP
- gin.Context with fallback value from gin.Context.Request.Context() #2751
BUGFIXES
- Fixed SetOutput() panics on go 1.17 #2861
- Fix: wrong when wildcard follows named param #2983
- Fix: missing sameSite when do context.reset() #3123
ENHANCEMENTS
- Use Header() instead of deprecated HeaderMap #2694
- RouterGroup.Handle regular match optimization of http method #2685
- Add support go-json, another drop-in json replacement #2680
- Use errors.New to replace fmt.Errorf will much better #2707
- Use Duration.Truncate for truncating precision #2711
- Get client IP when using Cloudflare #2723
- Optimize code adjust #2700
- Optimize code and reduce code cyclomatic complexity #2737
- gin.Context with fallback value from gin.Context.Request.Context() #2751
- Improve sliceValidateError.Error performance #2765
- Support custom struct tag #2720
- Improve router group tests #2787
- Fallback Context.Deadline() Context.Done() Context.Err() to Context.Request.Context() #2769
- Some codes optimize #2830 #2834 #2838 #2837 #2788 #2848 #2851 #2701
- Test(route): expose performRequest func #3012
- Support h2c with prior knowledge #1398
- Feat attachment filename support utf8 #3071
- Feat: add StaticFileFS #2749
- Feat(context): return GIN Context from Value method #2825
- Feat: automatically SetMode to TestMode when run go test #3139
- Add TOML bining for gin #3081
- IPv6 add default trusted proxies #3033
DOCS
- Add note about nomsgpack tag to the readme #2703