Improved performance
This commit is contained in:
11
Server.go
11
Server.go
@ -61,15 +61,20 @@ func (server *Server) Put(path string, handler Handler) {
|
||||
|
||||
// ServeHTTP responds to the given request.
|
||||
func (server *Server) ServeHTTP(response http.ResponseWriter, request *http.Request) {
|
||||
ctx := newContext(request, response, server)
|
||||
defer contextPool.Put(ctx)
|
||||
|
||||
ctx := contextPool.Get().(*ctx)
|
||||
ctx.request = request
|
||||
ctx.response = response
|
||||
ctx.server = server
|
||||
err := server.handlers[0](ctx)
|
||||
|
||||
if err != nil {
|
||||
response.(io.StringWriter).WriteString(err.Error())
|
||||
log.Println(request.URL, err)
|
||||
}
|
||||
|
||||
ctx.paramCount = 0
|
||||
ctx.handlerCount = 0
|
||||
contextPool.Put(ctx)
|
||||
}
|
||||
|
||||
// Run starts the server on the given address.
|
||||
|
Reference in New Issue
Block a user