mirror of
				https://github.com/gin-gonic/gin.git
				synced 2025-11-04 09:12:12 +08:00 
			
		
		
		
	Testing Copy() instead of Keep() and Release()
This commit is contained in:
		
							parent
							
								
									d9573b45c7
								
							
						
					
					
						commit
						d7a3fdcd8f
					
				
							
								
								
									
										32
									
								
								gin.go
									
									
									
									
									
								
							
							
						
						
									
										32
									
								
								gin.go
									
									
									
									
									
								
							@ -45,7 +45,6 @@ type (
 | 
				
			|||||||
		Errors   ErrorMsgs
 | 
							Errors   ErrorMsgs
 | 
				
			||||||
		Params   httprouter.Params
 | 
							Params   httprouter.Params
 | 
				
			||||||
		Engine   *Engine
 | 
							Engine   *Engine
 | 
				
			||||||
		keep     bool
 | 
					 | 
				
			||||||
		handlers []HandlerFunc
 | 
							handlers []HandlerFunc
 | 
				
			||||||
		index    int8
 | 
							index    int8
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
@ -174,6 +173,7 @@ func (engine *Engine) createContext(w http.ResponseWriter, req *http.Request, pa
 | 
				
			|||||||
		c.Req = req
 | 
							c.Req = req
 | 
				
			||||||
		c.Params = params
 | 
							c.Params = params
 | 
				
			||||||
		c.handlers = handlers
 | 
							c.handlers = handlers
 | 
				
			||||||
 | 
							c.Keys = nil
 | 
				
			||||||
		c.index = -1
 | 
							c.index = -1
 | 
				
			||||||
		return c
 | 
							return c
 | 
				
			||||||
	default:
 | 
						default:
 | 
				
			||||||
@ -181,7 +181,6 @@ func (engine *Engine) createContext(w http.ResponseWriter, req *http.Request, pa
 | 
				
			|||||||
			Writer:   w,
 | 
								Writer:   w,
 | 
				
			||||||
			Req:      req,
 | 
								Req:      req,
 | 
				
			||||||
			Params:   params,
 | 
								Params:   params,
 | 
				
			||||||
			keep:     false,
 | 
					 | 
				
			||||||
			handlers: handlers,
 | 
								handlers: handlers,
 | 
				
			||||||
			index:    -1,
 | 
								index:    -1,
 | 
				
			||||||
			Engine:   engine,
 | 
								Engine:   engine,
 | 
				
			||||||
@ -190,11 +189,9 @@ func (engine *Engine) createContext(w http.ResponseWriter, req *http.Request, pa
 | 
				
			|||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func (engine *Engine) reuseContext(c *Context) {
 | 
					func (engine *Engine) reuseContext(c *Context) {
 | 
				
			||||||
	if c.keep == false {
 | 
						select {
 | 
				
			||||||
		select {
 | 
						case engine.cache <- c:
 | 
				
			||||||
		case engine.cache <- c:
 | 
						default:
 | 
				
			||||||
		default:
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -272,21 +269,12 @@ func (group *RouterGroup) combineHandlers(handlers []HandlerFunc) []HandlerFunc
 | 
				
			|||||||
/****** FLOW AND ERROR MANAGEMENT****/
 | 
					/****** FLOW AND ERROR MANAGEMENT****/
 | 
				
			||||||
/************************************/
 | 
					/************************************/
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func (c *Context) Keep() {
 | 
					func (c *Context) Copy() *Context {
 | 
				
			||||||
	if c.keep == false {
 | 
						cp := &Context{}
 | 
				
			||||||
		c.keep = true
 | 
						*cp = *c
 | 
				
			||||||
	} else {
 | 
						cp.index = AbortIndex
 | 
				
			||||||
		log.Println("gin: trying to Keep same context several times")
 | 
						cp.handlers = nil
 | 
				
			||||||
	}
 | 
						return cp
 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
func (c *Context) Release() {
 | 
					 | 
				
			||||||
	if c.keep == true {
 | 
					 | 
				
			||||||
		c.keep = false
 | 
					 | 
				
			||||||
		c.Engine.reuseContext(c)
 | 
					 | 
				
			||||||
	} else {
 | 
					 | 
				
			||||||
		log.Println("gin: bug: trying to Release same context several times")
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// Next should be used only in the middlewares.
 | 
					// Next should be used only in the middlewares.
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user