mirror of https://github.com/gin-gonic/gin.git
Method initQueryCache is only called once
This commit is contained in:
parent
b860d8672d
commit
81a06fc629
|
@ -78,6 +78,9 @@ type Context struct {
|
|||
// SameSite allows a server to define a cookie attribute making it impossible for
|
||||
// the browser to send this cookie along with cross-site requests.
|
||||
sameSite http.SameSite
|
||||
|
||||
// Method initQueryCache is only called once
|
||||
initQueryCacheOnce sync.Once
|
||||
}
|
||||
|
||||
/************************************/
|
||||
|
@ -96,6 +99,7 @@ func (c *Context) reset() {
|
|||
c.Accepted = nil
|
||||
c.queryCache = nil
|
||||
c.formCache = nil
|
||||
c.initQueryCacheOnce = sync.Once{}
|
||||
*c.params = (*c.params)[0:0]
|
||||
}
|
||||
|
||||
|
@ -113,6 +117,7 @@ func (c *Context) Copy() *Context {
|
|||
cp.index = abortIndex
|
||||
cp.handlers = nil
|
||||
cp.Keys = map[string]interface{}{}
|
||||
cp.initQueryCacheOnce = sync.Once{}
|
||||
for k, v := range c.Keys {
|
||||
cp.Keys[k] = v
|
||||
}
|
||||
|
@ -431,6 +436,7 @@ func (c *Context) QueryArray(key string) []string {
|
|||
}
|
||||
|
||||
func (c *Context) initQueryCache() {
|
||||
c.initQueryCacheOnce.Do(func() {
|
||||
if c.queryCache == nil {
|
||||
if c.Request != nil {
|
||||
c.queryCache = c.Request.URL.Query()
|
||||
|
@ -438,6 +444,7 @@ func (c *Context) initQueryCache() {
|
|||
c.queryCache = url.Values{}
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
// GetQueryArray returns a slice of strings for a given query key, plus
|
||||
|
|
Loading…
Reference in New Issue