Merge branch 'master' into ctx

This commit is contained in:
田欧 2019-06-03 22:43:01 +08:00 committed by GitHub
commit 8670d38e7a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 28 additions and 14 deletions

View File

@ -63,6 +63,10 @@ type Context struct {
// queryCache use url.ParseQuery cached the param query result from c.Request.URL.Query() // queryCache use url.ParseQuery cached the param query result from c.Request.URL.Query()
queryCache url.Values queryCache url.Values
// formCache use url.ParseQuery cached PostForm contains the parsed form data from POST, PATCH,
// or PUT body parameters.
formCache url.Values
} }
/************************************/ /************************************/
@ -454,16 +458,24 @@ func (c *Context) PostFormArray(key string) []string {
return values return values
} }
// GetPostFormArray returns a slice of strings for a given form key, plus func (c *Context) getFormCache() {
// a boolean value whether at least one value exists for the given key. if c.formCache == nil {
func (c *Context) GetPostFormArray(key string) ([]string, bool) { c.formCache = make(url.Values)
req := c.Request req := c.Request
if err := req.ParseMultipartForm(c.engine.MaxMultipartMemory); err != nil { if err := req.ParseMultipartForm(c.engine.MaxMultipartMemory); err != nil {
if err != http.ErrNotMultipart { if err != http.ErrNotMultipart {
debugPrint("error on parse multipart form array: %v", err) debugPrint("error on parse multipart form array: %v", err)
} }
} }
if values := req.PostForm[key]; len(values) > 0 { c.formCache = req.PostForm
}
}
// GetPostFormArray returns a slice of strings for a given form key, plus
// a boolean value whether at least one value exists for the given key.
func (c *Context) GetPostFormArray(key string) ([]string, bool) {
c.getFormCache()
if values := c.formCache[key]; len(values) > 0 {
return values, true return values, true
} }
return []string{}, false return []string{}, false

2
go.mod
View File

@ -3,7 +3,7 @@ module github.com/gin-gonic/gin
go 1.12 go 1.12
require ( require (
github.com/gin-contrib/sse v0.0.0-20190301062529-5545eab6dad3 github.com/gin-contrib/sse v0.1.0
github.com/golang/protobuf v1.3.1 github.com/golang/protobuf v1.3.1
github.com/json-iterator/go v1.1.6 github.com/json-iterator/go v1.1.6
github.com/mattn/go-isatty v0.0.7 github.com/mattn/go-isatty v0.0.7

4
go.sum
View File

@ -1,7 +1,7 @@
github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8= github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/gin-contrib/sse v0.0.0-20190301062529-5545eab6dad3 h1:t8FVkw33L+wilf2QiWkw0UV77qRpcH/JHPKGpKa2E8g= github.com/gin-contrib/sse v0.1.0 h1:Y/yl/+YNO8GZSjAhjMsSuLt29uWRFHdHYUb5lYOV9qE=
github.com/gin-contrib/sse v0.0.0-20190301062529-5545eab6dad3/go.mod h1:VJ0WA2NBN22VlZ2dKZQPAPnyWw5XTlK1KymzLKsr59s= github.com/gin-contrib/sse v0.1.0/go.mod h1:RHrZQHXnP2xjPF+u1gW/2HnVO7nvIa9PG3Gm+fLHvGI=
github.com/golang/protobuf v1.3.1 h1:YF8+flBXS5eO826T4nzqPrxfhQThhXl0YzfuUPu4SBg= github.com/golang/protobuf v1.3.1 h1:YF8+flBXS5eO826T4nzqPrxfhQThhXl0YzfuUPu4SBg=
github.com/golang/protobuf v1.3.1/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= github.com/golang/protobuf v1.3.1/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
github.com/json-iterator/go v1.1.6 h1:MrUvLMLTMxbqFJ9kzlvat/rYZqZnW3u4wkLzWTaFwKs= github.com/json-iterator/go v1.1.6 h1:MrUvLMLTMxbqFJ9kzlvat/rYZqZnW3u4wkLzWTaFwKs=

8
vendor/vendor.json vendored
View File

@ -11,10 +11,12 @@
"versionExact": "v1.1.1" "versionExact": "v1.1.1"
}, },
{ {
"checksumSHA1": "QeKwBtN2df+j+4stw3bQJ6yO4EY=", "checksumSHA1": "qlEzrgKgIkh7y0ePm9BNo1cNdXo=",
"path": "github.com/gin-contrib/sse", "path": "github.com/gin-contrib/sse",
"revision": "5545eab6dad3bbbd6c5ae9186383c2a9d23c0dae", "revision": "54d8467d122d380a14768b6b4e5cd7ca4755938f",
"revisionTime": "2019-03-01T06:25:29Z" "revisionTime": "2019-06-02T15:02:53Z",
"version": "v0.1",
"versionExact": "v0.1.0"
}, },
{ {
"checksumSHA1": "Y2MOwzNZfl4NRNDbLCZa6sgx7O0=", "checksumSHA1": "Y2MOwzNZfl4NRNDbLCZa6sgx7O0=",