From 3f726c6ad8a1b1bcef49ab6c3e75f48cd1d10ebb Mon Sep 17 00:00:00 2001 From: daheige Date: Wed, 21 Apr 2021 22:03:44 +0800 Subject: [PATCH] adjust Copy method for gin Context --- context.go | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/context.go b/context.go index dc03c358..2647c9bc 100644 --- a/context.go +++ b/context.go @@ -48,7 +48,8 @@ type Context struct { Request *http.Request Writer ResponseWriter - Params Params + Params Params + // when the operation is not initialized, the default is nil slice handlers HandlersChain index int8 fullPath string @@ -107,12 +108,13 @@ func (c *Context) Copy() *Context { Request: c.Request, Params: c.Params, engine: c.engine, + Keys: make(map[string]interface{}, len(c.Keys)), + index: abortIndex, + handlers: nil, } + cp.writermem.ResponseWriter = nil cp.Writer = &cp.writermem - cp.index = abortIndex - cp.handlers = nil - cp.Keys = map[string]interface{}{} for k, v := range c.Keys { cp.Keys[k] = v }