gin v1.4.0 版本更新介绍
发布日期: 2019-05-08
版本号: v1.4.0
本次更新主要包含新功能添加及问题修复。新功能方面,新增对Go Modules、YAML绑定、URL参数绑定、PureJSON渲染的支持,优化表单映射、多部分请求处理、数组映射、日志格式(包含上下文键值、响应大小),扩展文件下载附件支持,增强重定向前缀处理,添加强制控制台颜色输出及基于文件描述符的服务器运行方法,并升级依赖库。问题修复涉及长请求延迟精度截断、日志颜色配置、静态文件404重复日志、敏感信息泄露、协程池使用、HTTP协商通配符支持、空JSON处理、URI参数绑定、恢复机制中的堆栈打印、上下文竞争条件等,同时调整日志格式、版权声明及测试配置,并将示例代码移至独立仓库。
更新内容 (中文)
功能特性
- [新增] 支持 Go Modules #1569
- [新增] 重构多部分请求的表单映射 #1829
- [新增] 支持文件绑定 #1264
- [新增] 添加对数组映射的支持 #1797
- [新增] 使 context.Keys 可在 LogFormatterParams 中使用 #1779
- [新增] 使用 internal/json 进行 Marshal/Unmarshal #1791
- [新增] 支持映射 time.Duration #1794
- [新增] 重构表单映射 #1749
- [新增] 为 context.Stream 添加标志,用于指示客户端是否在流过程中断开连接 #1252
- [新增] 扩展 context.File 以通过新方法 context.Attachment 支持 content-dispositon 附件 #1260
- [新增] 在 redirectTrailingSlash 中添加来自 X-Forwarded-Prefix 的前缀 #1238
- [新增] 添加 context.HandlerNames() #1729
- [新增] 在 LogFormatterParams 中添加响应大小 #1752
- [新增] 允许在表单映射中忽略字段 #1733
- [新增] 添加用于强制在控制台输出颜色的函数。 #1724
- [新增] URL 参数的绑定 #1694
- [新增] 添加 LoggerWithFormatter 方法 #1677
- [新增] RunFd 方法,用于通过文件描述符运行 http.Server #1609
- [新增] YAML 绑定支持 #1618
- [新增] 添加 PureJSON 渲染器 #694
- [新增] 在表单绑定中设置默认时间格式 #1487
- [新增] 升级依赖库 #1491
Bug 修复
- [修复] 在长时间运行的请求中截断延迟精度 #1830
- [修复] IsTerm 标志不应受 DisableConsoleColor 方法影响。 #1802
- [修复] Readme 更新 #1793 #1788 1789
- [修复] StaticFS: 修复 404 时记录两行日志的问题。 #1805, #1804
- [修复] 将 示例 移至独立仓库 #1775
- [修复] 支持 HTTP 内容协商通配符 #1112
- [修复] 调用 FormFile 时传递 MaxMultipartMemory #1600
- [修复] LoadHTML* 测试 #1559
- [修复] 从 HandleContext 中移除 sync.pool 的使用 #1565
- [修复] 将输出日志格式化为 os.Stderr #1571
- [修复] 使日志使用黄色背景和深灰色文本以提高可读性 #1570
- [修复] 从 panic 日志中移除敏感的请求信息。 #1370
- [修复] log.Println() 不打印时间戳 #829 #1560
- [修复] 添加缺失的版权信息和更新 if/else #1497
- [修复] 更新 msgpack 的使用 #1498
- [修复] 在渲染中使用 protobuf #1496
- [修复] 添加对 Protobuf 格式响应的支持 #1479
- [修复] 添加 BindXML 和 ShouldBindXML #1485
- [修复] CI 测试更新 #1671 #1670 #1682 #1669
- [修复] StaticFS(): 当路径不存在时发送 404 #1663
- [修复] 处理 JSON 绑定的 nil body #1638
- [修复] 支持绑定 uri 参数 #1612
- [修复] recovery: 修复在 Google App Engine 上使用 syscall 导入的问题 #1640
- [修复] 确保调试日志包含换行符 #1650
- [修复] 在恢复管道断裂期间打印 panic 堆栈跟踪 #1089 #1259
- [修复] Context.Next() - 在每次迭代时重新检查 handlers 的长度。 #1745
- [修复] 修复所有 errcheck 警告 #1739 #1653
- [修复] 将 defaultLogger 中的颜色方法改为公共方法。 #1771
- [修复] 更新 writeHeaders 方法以使用 http.Header.Set #1722
- [修复] context.Copy() 竞态条件 #1020
更新内容 (原始)
Feature
- [NEW] Support for Go Modules #1569
- [NEW] Refactor of form mapping multipart requesta #1829
- [NEW] Supporting file binding #1264
- [NEW] Add support for mapping arrays #1797
- [NEW] Make context.Keys available as LogFormatterParams #1779
- [NEW] Use internal/json for Marshal/Unmarshal #1791
- [NEW] Support mapping time.Duration #1794
- [NEW] Refactor form mappings #1749
- [NEW] Added flag to context.Stream indicates if client disconnected in middle of stream #1252
- [NEW] Extend context.File to allow for the content-dispositon attachments via a new method context.Attachment #1260
- [NEW] Add prefix from X-Forwarded-Prefix in redirectTrailingSlash #1238
- [NEW] Add context.HandlerNames() #1729
- [NEW] Add response size to LogFormatterParams #1752
- [NEW] Allow ignoring field on form mapping #1733
- [NEW] Add a function to force color in console output. #1724
- [NEW] Binding for URL Params #1694
- [NEW] Add LoggerWithFormatter method #1677
- [NEW] RunFd method to run http.Server through a file descriptor #1609
- [NEW] Yaml binding support #1618
- [NEW] Add PureJSON renderer #694
- [NEW] Set default time format in form binding #1487
- [NEW] Upgrade dependency libraries #1491
Bug fix
- [FIX] Truncate Latency precision in long running request #1830
- [FIX] IsTerm flag should not be affected by DisableConsoleColor method. #1802
- [FIX] Readme updates #1793 #1788 1789
- [FIX] StaticFS: Fixed Logging two log lines on 404. #1805, #1804
- [FIX] Moved examples to stand alone Repo #1775
- [FIX] Support HTTP content negotiation wildcards #1112
- [FIX] Pass MaxMultipartMemory when FormFile is called #1600
- [FIX] LoadHTML* tests #1559
- [FIX] Removed use of sync.pool from HandleContext #1565
- [FIX] Format output log to os.Stderr #1571
- [FIX] Make logger use a yellow background and a darkgray text for legibility #1570
- [FIX] Remove sensitive request information from panic log. #1370
- [FIX] log.Println() does not print timestamp #829 #1560
- [FIX] Add missing copyright and update if/else #1497
- [FIX] Update msgpack usage #1498
- [FIX] Use protobuf on render #1496
- [FIX] Add support for Protobuf format response #1479
- [FIX] Add BindXML and ShouldBindXML #1485
- [FIX] CI testing updates #1671 #1670 #1682 #1669
- [FIX] StaticFS(): Send 404 when path does not exist #1663
- [FIX] Handle nil body for JSON binding #1638
- [FIX] Support bind uri param #1612
- [FIX] recovery: fix issue with syscall import on google app engine #1640
- [FIX] Make sure the debug log contains line breaks #1650
- [FIX] Panic stack trace being printed during recovery of broken pipe #1089 #1259
- [FIX] Context.Next() - recheck len of handlers on every iteration. #1745
- [FIX] Fix all errcheck warnings #1739 #1653
- [FIX] Change color methods to public in the defaultLogger. #1771
- [FIX] Update writeHeaders method to use http.Header.Set #1722
- [FIX] context.Copy() race condition #1020