调整描述语句 (#1657)
Before adoption: this commit came in with the history the project adopted, so no landing records it.
调整描述语句
authored by weibaohui · committed by thinkerou · parent 1f576fb · Browse files · 1 file·+46 added−49 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
1 file+46 added−49 removed
- other:+46 added−49 removed
Provenance
- Commit
f52bea8- Tree
bff48ea- Author
weibaohui <weibaohui@yeah.net>- Committer
thinkerou <thinkerou@gmail.com>- Parent
1f576fb
1 file changed+46 added−49 removed
modified:README_ZH.md+46 added-49 removed
23 unmodified lines24 - [Gin v1 稳定版](#gin-v1-稳定版)25 - [使用 jsoniter 构建](#使用-jsoniter-构建)26 - [API 示例](#api-示例)27 - [GET,POST,PUT,PATCH,DELETE,OPTIONS 使用](#get-post-put-patch-delete-options-使用)28- - [路由参数](#路由参数)29- - [查询字符串参数](#查询字符串参数)28+ - [获取路由参数](#获取路由参数)29+ - [获取url查询参数](#获取url查询参数)30 - [Multipart Urlencoded 表单](#multipart-urlencoded-表单)31- - [另一个实列 query + post form](#另一个实列:-query-+-post-form)31+ - [获取post表单数据(url带查询参数)](#获取post表单数据(url带查询参数))32 - [映射参数 表单参数](#映射参数-表单参数)33 - [上传文件](#上传文件)34 - [路由组](#路由组)35 - [默认初始化 Gin](#默认初始化-gin)36- - [中间件使用](#中间件使用)36+ - [使用中间件](#使用中间件)37 - [如何记录日志](#如何记录日志)38 - [模型绑定和验证](#模型绑定和验证)39 - [自定义验证器](#自定义验证器)40- - [只绑定查询字符串](#只绑定查询字符串)41- - [绑定查询字符串或发布数据](#绑定查询字符串或发布数据)40+ - [只绑定url查询参数](#只绑定url查询参数)41+ - [url查询参数绑定到struct(或POST表单数据)](#url查询参数绑定到struct(或POST表单数据))42 - [绑定 HTML 复选框](#绑定-html-复选框)43 - [Multipart Urlencoded 绑定](#multipart-urlencoded-绑定)44 - [XML JSON YAML ProtoBuf 渲染](#xml-json-yaml-protobuf-渲染)45 - [SecureJSON](#SecureJSON)9 unmodified lines55 - [Let's Encrypt 支持](#lets-encrypt-支持)56 - [使用 Gin 运行多个服务](使用-gin-运行多个服务)57 - [优雅重启或停止](#优雅重启或停止)58 - [使用模板构建单个二进制文件](#使用模板构建单个二进制文件)59- - [使用自定义结构绑定表单数据请求](#使用自定义结构绑定表单数据请求)60- - [尝试将body绑定到不同的结构中](#尝试将-body-绑定到不同的结构中)59+ - [表单数据绑定到自定义结构体](#表单数据绑定到自定义结构体)60+ - [将request body绑定到不同的结构体中](#将request body绑定到不同的结构体中)61 - [http2 server 推送](#http2-server-推送)62 - [定义路由日志的格式](#定义路由日志的格式)63 - [测试](#测试)64 - [用户](#用户)39 unmodified lines104 $ govendor init105 $ govendor fetch github.com/gin-gonic/gin@v1.3106 ```107 108-4. 复制一个启动文件模板到项目目录中108+4. 复制启动文件模板到项目目录中109 110 ```sh111 $ curl https://raw.githubusercontent.com/gin-gonic/gin/master/examples/basic/main.go > main.go112 ```5 unmodified lines118 ```119 120 ## 前提条件121 122-新版本的 Gin 需要 Go 1.6 或者更高版本并且很快就会升级到 Go 1.7.122+新版本的 Gin 需要 Go 1.6 或者更高版本,并且很快就会升级到 Go 1.7.123 124 ## 快速启动125 126 ```sh106 unmodified lines233 // router.Run(":3000") for a hard coded port234 }235 ```236 237-### 路由参数237+### 获取路由参数238 239 ```go240 func main() {241 router := gin.Default()16 unmodified lines258 router.Run(":8080")259 }260 ```261 262-### 查询字符串参数262+### 获取url查询参数263 264 ```go265 func main() {266 router := gin.Default()29 unmodified lines296 router.Run(":8080")297 }298 ```299 300-### 另一个实列 query + post form300+### 获取post表单数据(url带查询参数)301 302 ```303 POST /post?id=1234&page=1 HTTP/1.1304 Content-Type: application/x-www-form-urlencoded74 unmodified lines379 router.Run(":8080")380 }381 ```382 383-如何 `curl`:383+`curl`示例:384 385 ```bash386 curl -X POST http://localhost:8080/upload \387 -F "file=@/Users/appleboy/test.zip" \25 unmodified lines413 router.Run(":8080")414 }415 ```416 417-如何 `curl`:417+`curl`示例:418 419 ```bash420 curl -X POST http://localhost:8080/upload \421 -F "upload[]=@/Users/appleboy/test1.zip" \42 unmodified lines464 r := gin.Default()465 ```466 467 468-### 中间件使用468+### 使用中间件469 ```go470 func main() {471 // Creates a router without any middleware by default472 r := gin.New()236 unmodified lines709 710 [结构级验证](https://github.com/go-playground/validator/releases/tag/v8.7)也可以这种方式注册。711 请参阅[struct-lvl-validation示例](examples/struct-lvl-validations)以了解更多信息。712 713-### 只绑定查询字符串713+### 只绑定url查询参数714 715-`ShouldBindQuery` 函数只绑定查询参数而不是后期数据。 请参阅[详细信息](https://github.com/gin-gonic/gin/issues/742#issuecomment-315953017)。715+`ShouldBindQuery` 函数只绑定url查询参数而不是post字段。 请参阅[详细信息](https://github.com/gin-gonic/gin/issues/742#issuecomment-315953017)。716 717 ```go718 package main719 25 unmodified lines745 }746 747 ```748 749-### 绑定查询字符串或发布数据749+### url查询参数绑定到struct(或POST表单数据)750 751 请参阅[详细信息](https://github.com/gin-gonic/gin/issues/742#issuecomment-264681292)。752 753 ```go117 unmodified lines871 router.Run(":8080")872 }873 ```874 875-Test it with:875+测试:876 ```sh877 $ curl -v --form user=user --form password=password http://localhost:8080/login878 ```879 118 unmodified lines998 ```999 1000 #### PureJSON1001 1002-通常,JSON 用其 unicod e实体替换特殊 HTML 字符,例如 `<` 变为 `\ u003c`。 如果要按字面意思对这些字符进行编码,则可以使用 PureJSON。1003-Go 1.6 及更低版本无法使用此功能。1002+通常,JSON使用unicode替换特殊HTML字符,例如 `<` 变为 `\ u003c`。 如果要按字面意思对这些字符进行编码,则可以使用 PureJSON。1003+Go 1.6及更低版本无法使用此功能。1004 1005 ```go1006 func main() {1007 r := gin.Default()373 unmodified lines1381 ```1382 1383 ### Let's Encrypt 支持1384 1385-单行 LetsEncrypt HTTPS 服务器的示例。1385+一行代码支持 LetsEncrypt HTTPS示例。1386 1387 [embedmd]:# (examples/auto-tls/example1/main.go go)1388 ```go1389 package main16 unmodified lines1406 log.Fatal(autotls.Run(r, "example1.com", "example2.com"))1407 }1408 ```1409 1410-自定义autocert管理器的示例。1410+autocert使用示例。1411 1412 [embedmd]:# (examples/auto-tls/example2/main.go go)1413 ```go1414 package main119 unmodified lines1534 // [...]1535 endless.ListenAndServe(":4242", router)1536 ```1537 1538-另一种替代方案:1538+替代方案:1539 1540 * [manners](https://github.com/braintree/manners):礼貌的Go HTTP服务器,可以正常关闭。1541 * [graceful](https://github.com/tylerb/graceful):Graceful是一个Go包,可以正常关闭http.Handler服务器。1542 * [grace](https://github.com/facebookgo/grace):Go服务器的平滑重启和零停机时间部署。1543 1544-如果您使用的是Go 1.8,则可能不需要使用此库! 考虑使用http.Server的内置[Shutdown()](https://golang.org/pkg/net/http/#Server.Shutdown)方法进行正常关机。 请参阅gin的完整[graceful-shutdown](./examples /graceful-shutdown)示例。1544+如果您使用的是Go 1.8,可以考虑使用http.Server内置[Shutdown()](https://golang.org/pkg/net/http/#Server.Shutdown)方法进行正常关机。 请参阅gin的完整[graceful-shutdown](./examples /graceful-shutdown)示例。1545 1546 [embedmd]:# (examples/graceful-shutdown/graceful-shutdown/server.go go)1547 ```go1548 // +build go1.847 unmodified lines1596 ```1597 1598 ### 使用模板构建单个二进制文件1599 1600-您可以使用[go-assets] []将服务器构建到包含模板的单个二进制文件中。1600+您可以使用[go-assets]将服务器打包为包含模板的单个二进制可执行文件。1601 1602 [go-assets]:https://github.com/jessevdk/go-assets1603 1604 ```go33 unmodified lines1638 ```1639 1640 请参阅`examples/assets-in-binary`目录中的完整示例。1641 1642-### Bind form-data request with custom struct1642+### 表单数据绑定到自定义结构体1643 1644 以下示例使用自定义结构:1645 1646 ```go83 unmodified lines1730 ```1731 1732 总之,只支持现在没有`form`的嵌套自定义结构。1733 1734-### 尝试将 body 绑定到不同的结构中1734+### 将request body绑定到不同的结构体中1735 1736-绑定请求体的常规方法使用`c.Request.Body`和它们1737-不能多次调用。1736+一般通过调用`c.Request.Body`方法绑定数据,但不能多次调用这个方法。1737 1738 ```go1739 type formA struct {1740 Foo string `json:"foo" xml:"foo" binding:"required"`17 unmodified lines1758 }1759 }1760 ```1761 1763-为此,您可以使用`c.ShouldBindBodyWith`.1762+为此,要想多次绑定,需要使用`c.ShouldBindBodyWith`.1763 1764 ```go1765 func SomeHandler(c *gin.Context) {1766 objA := formA{}13 unmodified lines1780 }1781 ```1782 1783 1785-482/50001786-*`c.ShouldBindBodyWith`在绑定之前将body存储到上下文中。 这有1787-对性能有轻微影响,所以如果你这样做,你不应该使用这种方法1788-足以立刻调用绑定。1789-*只有某些格式需要此功能 - “JSON”,“XML”,“MsgPack”,1790-`ProtoBuf`。 对于其他格式,`Query`,`Form`,`FormPost`,`FormMultipart`,1791-可以被`c.ShouldBind()`多次调用而不会造成任何损害1792-表现(见[#1341](https://github.com/gin-gonic/gin/pull/1341)。1784+*`c.ShouldBindBodyWith`会在绑定之前将body存储到上下文中。 这会1785+对性能造成轻微影响,如果调用一次就能完成绑定的话,那就不要用这个方法。1786+*只有某些格式需要此功能 ,如“JSON”,“XML”,“MsgPack”,1787+`ProtoBuf`。 对于其他格式,如`Query`,`Form`,`FormPost`,`FormMultipart`,1788+可以多次调用`c.ShouldBind()`而不会造成任任何性能损失(见[#1341](https://github.com/gin-gonic/gin/pull/1341))。1789 1790 ### http2 server 推送1791 1792 45 unmodified lines1838 ```1839 1840 ### 定义路由日志的格式1841 1846-路由的默认日志是:1842+默认的路由日志格式:1843 ```1844 [GIN-debug] POST /foo --> main.main.func1 (3 handlers)1845 [GIN-debug] GET /bar --> main.main.func2 (3 handlers)1846 [GIN-debug] GET /status --> main.main.func3 (3 handlers)1847 ```1848 1853-如果要以给定格式记录此信息(例如JSON,键值或其他内容),则可以使用`gin.DebugPrintRouteFunc`定义此格式。1854-在下面的示例中,我们使用标准日志包记录所有路由,但您可以使用其他适合您需求的日志工具。1849+如果要以指的格式(例如JSON,Key Values或其他格式)记录信息,则可以使用`gin.DebugPrintRouteFunc`指定格式。1850+在下面的示例中,我们使用标准日志包记录所有路由,但您可以使用其他满足需求的日志工具。1851 ```go1852 import (1853 "log"1854 "net/http"26 unmodified lines1881 1882 1883 ## 测试1884 1889-`net/http/httptest`包是HTTP测试的首选方式。1885+HTTP测试首选`net/http/httptest`包。1886 1887 ```go1888 package main1889 10 unmodified lines1900 r.Run(":8080")1901 }1902 ```1903 1908-测试上面的代码示例:1904+上面这段代码的测试用例:1905 1906 ```go1907 package main1908 19 unmodified lines1928 1929 ## 用户1930 1931 1936-使用[Gin](https://github.com/gin-gonic/gin)Web框架的令人尊敬的项目列表。1932+使用[Gin](https://github.com/gin-gonic/gin)框架的著名项目。1933 1938-* [drone](https://github.com/drone/drone):drone,用Go编写。1939-* [gorush](https://github.com/appleboy/gorush):用Go编写的推送通知服务器。1940-* [fnproject](https://github.com/fnproject/fn):容器本机,云无关的无服务器平台。1934+* [drone](https://github.com/drone/drone):用Go编写的基于docker的持续集成平台。1935+* [gorush](https://github.com/appleboy/gorush):用Go编写的推送通知服务。1936+* [fnproject](https://github.com/fnproject/fn):容器驱动、云无关的无服务器平台。1937+* [photoprism](https://github.com/photoprism/photoprism): 用Go编写的基于TensorFlow的个人相册管理系统.